Question

In: Computer Science

Translate the following C program to Pep/9 assembly language. #include <stdio.h> int main(){ int numItms, j,...

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);

return 0;

}

SAMPLE INPUT: 48-376

SAMPLE OUTPUT: Sum: 18

Solutions

Expert Solution

   .file   "ex.c"
   .text
   .section   .rodata
.LC0:
   .string   "%d"
.LC1:
   .string   "Sum:%d\n"
   .text
   .globl   main
   .type   main, @function
main:
.LFB0:
   .cfi_startproc
   pushq   %rbp
   .cfi_def_cfa_offset 16
   .cfi_offset 6, -16
   movq   %rsp, %rbp
   .cfi_def_cfa_register 6
   subq   $32, %rsp
   movq   %fs:40, %rax
   movq   %rax, -8(%rbp)
   xorl   %eax, %eax
   leaq   -24(%rbp), %rax
   movq   %rax, %rsi
   leaq   .LC0(%rip), %rdi
   movl   $0, %eax
   call   __isoc99_scanf@PLT
   movl   $0, -12(%rbp)
   movl   $1, -16(%rbp)
   jmp   .L2
.L3:
   leaq   -20(%rbp), %rax
   movq   %rax, %rsi
   leaq   .LC0(%rip), %rdi
   movl   $0, %eax
   call   __isoc99_scanf@PLT
   movl   -20(%rbp), %eax
   addl   %eax, -12(%rbp)
   addl   $1, -16(%rbp)
.L2:
   movl   -24(%rbp), %eax
   cmpl   %eax, -16(%rbp)
   jle   .L3
   movl   -12(%rbp), %eax
   movl   %eax, %esi
   leaq   .LC1(%rip), %rdi
   movl   $0, %eax
   call   printf@PLT
   movl   $0, %eax
   movq   -8(%rbp), %rdx
   xorq   %fs:40, %rdx
   je   .L5
   call   __stack_chk_fail@PLT
.L5:
   leave
   .cfi_def_cfa 7, 8
   ret
   .cfi_endproc
.LFE0:
   .size   main, .-main
   .ident   "GCC: (Ubuntu 7.4.0-1ubuntu1~18.04.1) 7.4.0"
   .section   .note.GNU-stack,"",@progbits

This is the assembly code generated on an ubuntu machine


Related Solutions

Translate the following C program to PEP/9 assembly language. #include <stdio.h> Int main (){ int number;...
Translate the following C program to PEP/9 assembly language. #include <stdio.h> Int main (){ int number; Scanf (“%d”, & number); if (number % 2 ==0) { printf (“Even\n”); } else { printf(“Odd\n”); } Return 0; }
Translate the following C program to Pep/9 assembly language. #include <stdio.h.> int main() { int numitms,j,data,sum;...
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; } I got an answer with an error. Please debug the answer or have a new correct answer (don't copy and paste others' answer) 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...
Translate the following C program to Pep/9 assembly language: #include <stdio.h> char toLower(char ch) { if...
Translate the following C program to Pep/9 assembly language: #include <stdio.h> char toLower(char ch) { if (ch >= 'A' && ch <= 'Z' )        ch += 'a' - 'A'; return ch; } int main() { char ch, conversion; printf("Enter an uppercase letter: "); scanf("%c", &ch); conversion = toLower(ch); printf("\nLetter after conversion: %c\n\n", conversion); return 0; }
Take the following program and translate it into PEP/9 assembly language: #include using namespace std; int...
Take the following program and translate it into PEP/9 assembly language: #include using namespace std; int fib(int n) { int temp; if (n <= 0) return 0; else if (n <= 2) return 1; else { temp = fib(n – 1); return temp + fib(n-2); } } int main() { int num; cout << "Which fibonacci number? "; cin >> num; cout << fib(num) << endl; return 0; } You must use equates to access the stack and follow the...
Take the following C++ program and translate it into Pep/9 assembly language #include using namespace std;...
Take the following C++ program and translate it into Pep/9 assembly language #include using namespace std; int age; char first, last; int main() {    cin >> age;    cin >> first >> last;    cout << "Your age " << age << endl;    cout << "Initials " << first << last << endl;    if (age >= 30)        cout << “Cannot trust\n”;    return 0; }
Take the following C++ program and translate it into PEP/9 assembly language #include <iostream> using namespace...
Take the following C++ program and translate it into PEP/9 assembly language #include <iostream> using namespace std; int num; char letter; int main() {    cin >> num;    cin >> letter;    cout << "You inputted " << num << endl;    cout << "Option " << letter << endl;    if (letter == '*')       cout << "Multiplied by 2 " << num*2 << endl;    return 0; }
Take the following program from C++ and translate it into Pep/9 assembly language: #include <iostream> using...
Take the following program from C++ and translate it into Pep/9 assembly language: #include <iostream> using namespace std; int theArray[] = { 5, 11, -29, 45, 9, -1}; void sumPos(int ary[], int len, int &sum) {    sum = 0;    for (int i = 0; i < len; i++)            if (ary[i] > 0)                sum = sum + ary[i]; } int main() {    int total;    sumPos(theArray, 6, total);    for (int k=0; k < 6; k++)...
1) Translate the following C program to Pep/9 assembly language. Please attach screenshot of Pep/9 simulator...
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; }
Take the following program and translate it into PEP/9 assembly language: #include <iostream> using namespace std;...
Take the following program and translate it into PEP/9 assembly language: #include <iostream> using namespace std; int theArray[] = { 5, 11, -29, 45, 9, -1}; void sumPos(int ary[], int len, int &sum) {    sum = 0;    for (int i = 0; i < len; i++)            if (ary[i] > 0)                sum = sum + ary[i]; } int main() {    int total;    sumPos(theArray, 6, total);    for (int k=0; k < 6; k++)      cout...
Translate the following C++ program to Pep/9 assembly language. const char chConst = '+'; char ch1;...
Translate the following C++ program to Pep/9 assembly language. const char chConst = '+'; char ch1; char ch2; int main() { cin.get(ch1); cin.get(ch2);    cout << ch1 << chConst << ch2;    return 0; }
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT