Question: Below is C code for a fibonacci sequence and it translated into assembly. Can you explain line by line how each was translated from C
Below is C code for a fibonacci sequence and it translated into assembly. Can you explain line by line how each was translated from C to assembly? Thanks
C code:
long fibonaccigdgotolong
long ;
long next, first second ;
if
goto done
loop:
next first second;
first second; second next;
i;
if
goto loop;
done:
return ;
Assembly Code:
fibonacci:
pushq rbp
movq rsprbp
movq rdi, rbp
movq $rbp
movq $rbp
movq $rbp
cmpq $rbp
jle L
nop
L:
movq rbprdx
movq rbprax
addq rdxrax
movq rax, rbp
movq rbprax
movq rax, rbp
movq rbprax
movq rax, rbp
addq $rbp
movq rbprax
cmpq rbprax
jg L
jmp L
L:
nop
jmp L
L:
nop
L:
movq rbprax
popq rbp
ret
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
