Translate the following C program to Pep/9 assembly language.
#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;
}
Please test the answer using Pep/9. Thank you so much!
The Pep/9 translation the C code in the assembly language is given as follows:
main: SUBSP 2,i
DECI numItms,i
DECI j,j
DECI data,d
DECI sum,s
LDWA numItms,i
sum: .EQUATE 0
LDWA 1,i
STWA j,j
for: CPWA numItms, j
BRGE endFor
STRO msg,d
DECO j,s
LDBA '\n',i
STBA charOut,d
LDWA j,s ;j++)
ADDA 1,i
STWA j,s
BR for
endFor: ADDSP 2,i ; STOP
msg: .ASCII "Sum = \x00"
.END
------------------------------------------------
The above given code is the translation of the C code into the Pep 9 assembly language.
---------------------------------------------------Please Upvote-------------------------------------------------------
Get Answers For Free
Most questions answered within 1 hours.