0% found this document useful (0 votes)
50 views3 pages

Compiler

from assignment

Uploaded by

siskali715
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
50 views3 pages

Compiler

from assignment

Uploaded by

siskali715
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

WOLLO UNIVERSITY

KOMBOLCHA INSTITUTES OF TECHNOLOGY


COLLEGE OF INFORMATICS
THESIS TEMpLATE

COMpILER DESIGN ASSIGNMENT

Name:kalkidan sisay

ID: 1450/13

Summited to:Anteneh E

Due Date:04/06/2026
1. Show assembly language for a machine of your choice, corresponding to each of
the following C/C++ statements:
A. A = B + C;
mov eax, [B] ;
add eax, [C] ;
mov [A], eax ;
B. A = (B+C) ∗ (C-D);
mov eax, [B] ;
add eax, [C] ;
mov ecx, eax ;
mov eax, [C] ;
sub eax, [D] ;
imul eax, ecx ;
mov [A], eax ;
C. for (I=1; I<=10; I++) A = A+I;
mov ecx, 1 ;
loop_start:
mov eax, [A] ;
add eax, ecx ;
mov [A], eax ;
inc ecx ;
cmp ecx, 10 ;
jle loop_start ;
2. Show the difference between compiler output and interpreter output for each of
the following source inputs:
a) A = 12;
B = 6;
C = A+B;
cout <<C<<A<<B;
Compiler output: Machine code for each statement.
Interpreter output: Immediate execution of each statement.
b) A = 12;
B = 6;
if (A<B) cout << A;
else cout << B;
Compiler output:
Machine code for each statement in sequence.
Interpreter output:
Execution of statements line by line with immediate results.
c) A = 12;
B = 6;
while (B<A)
{ A = A-1;
cout << A << B << endl;}
Compiler output: Machine code that implements the while loop, decrementing A
and printing values until B >= A.
Interpreter output: Executes the while loop, decrementing A and printing values
until B >= A.
3. Which of the following C/C++ source errors would be detected at compile time,
and which would be detected at run time?
(a) A = B+C = 3; Compile-time error
(b) if (X<3) A = 2
else A = X; Compile time error
(c) if (A>0) X = 20;
else if (A<0) X = 10;
else X = X/A;Run-time error

(d) while ((p->info>0) && (p!=0))


p = p->next;
/* assume p points to a struct
named node with
these field definitions:
int info; Compile-time error
4. Using the big C notation, show the symbol for each of the following:
(a) A compiler which translates COBOL source programs to PC machine language and
runs on a PC. COBOL compiler on PC: COBOL -> PC -> PC (CPC)
(b) A compiler, written in Java, which translates FORTRAN source programs to Mac
machine language. FORTRAN compiler in Java on Mac: FORTRAN -> Mac -> Java (FM
(c) A compiler, written in Java, which translates Sun machine language programs to
Java. Java compiler translating Sun to Java: Sun -> Java -> Java (SJJ)

You might also like