Convert the following C code to assembler:
a) unsigned char A, B, C;
if (A > B) C = A;
elseif (A == B) C = 0;
else C = B;
b) unsigned char A, B;
A = 228;
B = A/4;
c) unsigned char A, B;
A = 228;
B = A/5;
Below is he solution:
A)
main:
push rbp
mov rbp, rsp
movzx eax, BYTE PTR [rbp-1]
cmp al, BYTE PTR [rbp-2]
jbe .L2
movzx eax, BYTE PTR [rbp-1]
mov BYTE PTR [rbp-3], al
jmp .L3
.L2:
movzx eax, BYTE PTR [rbp-1]
cmp al, BYTE PTR [rbp-2]
jne .L4
movzx eax, BYTE PTR [rbp-1]
mov BYTE PTR [rbp-3,0
jmp .L3
.L4:
movzx eax, BYTE PTR [rbp-1]
mov BYTE PTR [rbp-3], al
.L3:
mov eax,0
pop rbp
ret
B)
main:
push rbp
mov rbp, rsp
mov BYTE PTR [rbp-1], -28
movzx eax, BYTE PTR [rbp-1]
shr al,2
mov BYTE PTR [rbp-2],al
mov eax,0
pop rbp
ret
C)
Get Answers For Free
Most questions answered within 1 hours.