78 439
Assignments Done
Successfully Done
In September 2019

Answer to Question #25102 in C++ for eric

Question #25102
convert this c++ code in to assembly.. for (a=0; a<=y; a++) for (b=0; b<=y/2; b++) for (c=0; c<=y/3; c++) if ((a + 2*b + 3*c) == y) count++;
Expert's answer
.file &quot;asm.cpp&quot;
.globl main
.type main, @function
pushl %ebp
.cfi_def_cfa_offset 8
.cfi_offset 5, -8
movl %esp, %ebp
.cfi_def_cfa_register 5
subl $32, %esp
movl $0, -20(%ebp)
jmp .L2
movl $0, -16(%ebp)
jmp .L3
movl $0, -12(%ebp)
jmp .L4
movl -16(%ebp), %eax
leal (%eax,%eax), %edx
movl -20(%ebp), %eax
leal (%edx,%eax), %ecx
movl -12(%ebp), %edx
movl %edx, %eax
addl %eax, %eax
addl %edx, %eax
addl %ecx, %eax
cmpl -4(%ebp), %eax
jne .L5
addl $1, -8(%ebp)
addl $1, -12(%ebp)
movl -4(%ebp), %ecx
movl $1431655766, %edx
movl %ecx, %eax
imull %edx
movl %ecx, %eax
sarl $31, %eax
movl %edx, %ecx
subl %eax, %ecx
movl %ecx, %eax
cmpl -12(%ebp), %eax
setge %al
testb %al, %al
jne .L6
addl $1, -16(%ebp)
movl -4(%ebp), %eax
movl %eax, %edx
shrl $31, %edx
addl %edx, %eax
sarl %eax
cmpl -16(%ebp), %eax
setge %al
testb %al, %al
jne .L7
addl $1, -20(%ebp)
movl -20(%ebp), %eax
cmpl -4(%ebp), %eax
setle %al
testb %al, %al
jne .L8
movl $0, %eax
.cfi_restore 5
.cfi_def_cfa 4, 4
.size main, .-main
.ident &quot;GCC: (Ubuntu/Linaro 4.7.2-2ubuntu1) 4.7.2&quot;
.section .note.GNU-stack,&quot;&quot;,@progbits

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!


No comments. Be first!

Leave a comment

Ask Your question

Privacy policy Terms and Conditions