Compiler
Compiler
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