In: Computer Science
1) Translate the following C program to Pep/9 assembly language. Please attach screenshot of Pep/9 simulator running the program.
#include <stdio.h.>
int main() {
int numitms,j,data,sum;
scanf("%d", &numitms);
sum=0;
for (j=1;j<=numitms;j++) {
scanf("%d", &data);
sum+=data;
}
printf("sum: %d\n",sum);
return0;
}
Converted Code:
.LC0:
.string "%d"
.LC1:
.string "sum: %d\n"
main:
push rbp
mov rbp, rsp
sub rsp, 16
lea rax, [rbp-12]
mov rsi, rax
mov edi, OFFSET FLAT:.LC0
mov eax, 0
call __isoc99_scanf
mov DWORD PTR [rbp-8], 0
mov DWORD PTR [rbp-4], 1
jmp .L2
.L3:
lea rax, [rbp-16]
mov rsi, rax
mov edi, OFFSET FLAT:.LC0
mov eax, 0
call __isoc99_scanf
mov eax, DWORD PTR [rbp-16]
add DWORD PTR [rbp-8], eax
add DWORD PTR [rbp-4], 1
.L2:
mov eax, DWORD PTR [rbp-12]
cmp DWORD PTR [rbp-4], eax
jle .L3
mov eax, DWORD PTR [rbp-8]
mov esi, eax
mov edi, OFFSET FLAT:.LC1
mov eax, 0
call printf
mov eax, 0
leave
ret
Screenshots:
Note: If you have any doubts or queries, feel free to ask by commenting down below.
And if my answer suffice to the requirements, then kindly upvote as an appreciation
Happy Learning :)