Write an assembly language program that corresponds to the following C program:
ID: 3809314 • Letter: W
Question
Write an assembly language program that corresponds to the following C program: char ch: int main () {scanf (# c*, & ch}: ch --; print f (c *, ch}; return 0; Write an assembly language program that corresponds to the following C program: C program jnc num1; int num 2; int main () {scanf (numl1/num2 = num1; print f (" num 1 = d ", num 1); print f (" num 2 = d ", num 2); Write an assembly language program that corresponds to the following C program: inc num; inc main () {(scanf{"%d", & num); num = num/16; printf("num - %d ". num); return 0;Explanation / Answer
28.
#include <stdio.h>
char ch;
int main()
{
scanf("%c", &ch);
ch--;
printf("%c ",ch);
return 0;
}
-----------------------Assembaly language -------------------------------
ch:
.zero 1
.LC0:
.string "%c"
.LC1:
.string "%c "
main:
push rbp
mov rbp, rsp
mov esi, OFFSET FLAT:ch
mov edi, OFFSET FLAT:.LC0
mov eax, 0
call scanf
movzx eax, BYTE PTR ch[rip]
sub eax, 1
mov BYTE PTR ch[rip], al
movzx eax, BYTE PTR ch[rip]
movsx eax, al
mov esi, eax
mov edi, OFFSET FLAT:.LC1
mov eax, 0
call printf
mov eax, 0
pop rbp
ret
29).
#include <stdio.h>
int num1;
int num2;
int main()
{
scanf("%d", &num1);
num2 = -num1;
printf("num1= %d ", num1);
printf("num2= %d ", num2);
return 0;
}
------------------------Assembally language---------------------------------------------------
num1:
.zero 4
num2:
.zero 4
.LC0:
.string "%d"
.LC1:
.string "num1= %d "
.LC2:
.string "num2= %d "
main:
push rbp
mov rbp, rsp
mov esi, OFFSET FLAT:num1
mov edi, OFFSET FLAT:.LC0
mov eax, 0
call scanf
mov eax, DWORD PTR num1[rip]
neg eax
mov DWORD PTR num2[rip], eax
mov eax, DWORD PTR num1[rip]
mov esi, eax
mov edi, OFFSET FLAT:.LC1
mov eax, 0
call printf
mov eax, DWORD PTR num2[rip]
mov esi, eax
mov edi, OFFSET FLAT:.LC2
mov eax, 0
call printf
mov eax, 0
pop rbp
ret
30).
#include <stdio.h>
int num;
int main()
{
scanf("%d", &num);
num=num/16;
printf("num= %d ", num);
return 0;
}
------------------------------Assembally code------------------------------------------
num:
.zero 4
.LC0:
.string "%d"
.LC1:
.string "num= %d "
main:
push rbp
mov rbp, rsp
mov esi, OFFSET FLAT:num
mov edi, OFFSET FLAT:.LC0
mov eax, 0
call scanf
mov eax, DWORD PTR num[rip]
lea edx, [rax+15]
test eax, eax
cmovs eax, edx
sar eax, 4
mov DWORD PTR num[rip], eax
mov eax, DWORD PTR num[rip]
mov esi, eax
mov edi, OFFSET FLAT:.LC1
mov eax, 0
call printf
mov eax, 0
pop rbp
ret
Hope this will help you :)
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.