In: Computer Science
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
.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