Convert the following C code to Pep9 Assembly . Please do not use any version of
ID: 3799915 • Letter: C
Question
Convert the following C code to Pep9 Assembly. Please do not use any version of Assembly but Pep9. This is the FIFTH time I'm asking this question because people replying continue to use Intel x86 or other languages that are not Pep9 Assembly. Answers not in Pep9 will be thumbs downed. The last person just copy and pasted my C code and resubmitted it...
THIS MUST BE PEP9 ASSEMBLY, NOT INTEL X86.
This is an example of what Pep9 looks like: http://i.imgur.com/1B2f1PL.png
Problem below:
Convert the following C code to Pep9 Assembly.
#include
#include
int n = 0;
int main()
{
printf("N: ");
scanf("%d", &n);
int r = n * 0.875;
int boxes = r / 16;
int individual = r % 16;
int total = (boxes * 8) + (individual * 2);
printf("Cost to ship is $%d", total);
return 0;
}
Explanation / Answer
code:
.globl n
.bss
.align 4
.type n, @object
.size n, 4
n:
.zero 4
.section .rodata
.LC0:
.string "N: "
.LC1:
.string "%d"
.LC3:
.string "Cost to ship is $%d"
.text
.globl main
.type main, @function
main:
.LFB0:
pushq %rbp
movq %rsp, %rbp
subq $16, %rsp
movl $.LC0, %edi
movl $0, %eax
call printf
movl $n, %esi
movl $.LC1, %edi
movl $0, %eax
call __isoc99_scanf
movl n(%rip), %eax
pxor %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
movsd .LC2(%rip), %xmm1
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
movl %eax, -16(%rbp)
movl -16(%rbp), %eax
leal 15(%rax), %edx
testl %eax, %eax
cmovs %edx, %eax
sarl $4, %eax
movl %eax, -12(%rbp)
movl -16(%rbp), %eax
shrl $28, %edx
addl %edx, %eax
andl $15, %eax
subl %edx, %eax
movl %eax, -8(%rbp)
movl -12(%rbp), %eax
leal 0(,%rax,4), %edx
movl -8(%rbp), %eax
addl %edx, %eax
addl %eax, %eax
movl %eax, -4(%rbp)
movl -4(%rbp), %eax
movl %eax, %esi
movl $.LC3, %edi
movl $0, %eax
call printf
movl $0, %eax
leave
ret