63 063
Assignments Done
99,1%
Successfully Done
In July 2018

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;
.text
.globl main
.type main, @function
main:
.LFB0:
.cfi_startproc
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
.L8:
movl $0, -16(%ebp)
jmp .L3
.L7:
movl $0, -12(%ebp)
jmp .L4
.L6:
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)
.L5:
addl $1, -12(%ebp)
.L4:
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)
.L3:
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)
.L2:
movl -20(%ebp), %eax
cmpl -4(%ebp), %eax
setle %al
testb %al, %al
jne .L8
movl $0, %eax
leave
.cfi_restore 5
.cfi_def_cfa 4, 4
ret
.cfi_endproc
.LFE0:
.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!

Comments

No comments. Be first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions