Write a fragment of assembly language equivalent of the foll
Write a fragment of assembly language equivalent of the following C code. Allocate variables in data memory locations of your own choosing.
int16 a,b;
int8 c,d;
a=5;
c=a--;
b=1-c+a;
d=((a|b)&c)<<2;
Solution
Lets take the name of this function as main.
So the equivalent assembly code goes as follows:
main:
push rbp
mov rbp, rsp
mov DWORD PTR [rbp-4], 5
mov eax, DWORD PTR [rbp-4]
lea edx, [rax-1]
mov DWORD PTR [rbp-4], edx
mov DWORD PTR [rbp-8], eax
mov eax, 1
sub eax, DWORD PTR [rbp-8]
mov edx, eax
mov eax, DWORD PTR [rbp-4]
add eax, edx
mov DWORD PTR [rbp-12], eax
mov eax, DWORD PTR [rbp-4]
or eax, DWORD PTR [rbp-12]
and eax, DWORD PTR [rbp-8]
sal eax, 2
mov DWORD PTR [rbp-16], eax
mov eax, 0
pop rbp
ret
