Embed presentation
Download to read offline
![Write the following statement in C, in Assembly language unsigned char i, j, k; j = 10; do {k
= k + I; j = j + 1;} while(j! = 18);//... rest of code ...
Solution
//assembly code is as follows
//please include int main() uncion in your asssembly code
main:
push rbp
mov rbp, rsp
mov BYTE PTR [rbp-1], 10
.L3:
movzx eax, BYTE PTR [rbp-3]
add BYTE PTR [rbp-2], al
add BYTE PTR [rbp-1], 1
cmp BYTE PTR [rbp-1], 18
je .L2
jmp .L3
.L2:
mov eax, 0
pop rbp
ret](https://image.slidesharecdn.com/writethefollowingstatementincinassemblylanguageunsignedch-230706141445-33259cd4/75/Write-the-following-statement-in-C-in-Assembly-language-unsigned-ch-pdf-1-2048.jpg)
This document contains C code and its equivalent assembly code translation. The C code declares three unsigned char variables i, j, k and initializes j to 10. It then enters a do-while loop that increments k by i and j by 1 on each iteration, looping until j is no longer not equal to 18. The assembly code translation of this C code initializes j to 10, loads i and k onto the stack, enters a loop that adds i to k and increments j by 1, compares j to 18, and continues looping until j is equal to 18.
![Write the following statement in C, in Assembly language unsigned char i, j, k; j = 10; do {k
= k + I; j = j + 1;} while(j! = 18);//... rest of code ...
Solution
//assembly code is as follows
//please include int main() uncion in your asssembly code
main:
push rbp
mov rbp, rsp
mov BYTE PTR [rbp-1], 10
.L3:
movzx eax, BYTE PTR [rbp-3]
add BYTE PTR [rbp-2], al
add BYTE PTR [rbp-1], 1
cmp BYTE PTR [rbp-1], 18
je .L2
jmp .L3
.L2:
mov eax, 0
pop rbp
ret](https://image.slidesharecdn.com/writethefollowingstatementincinassemblylanguageunsignedch-230706141445-33259cd4/75/Write-the-following-statement-in-C-in-Assembly-language-unsigned-ch-pdf-1-2048.jpg)