The assembly language for bar() is: (gdb) disass bar 0x00000000004004f0 : push %
ID: 3854888 • Letter: T
Question
The assembly language for bar() is: (gdb) disass bar 0x00000000004004f0 : push %rbp 0x00000000004004f1 : mov %rsp, %rbp 0x00000000004004f4 s mov %edi, -0xl4 (%rbp) 0x00000000004004f7 : mov -0x14 (%rbp), %eax 0x00000000004004fa : imul -0x14 (%rbp), %eax 0x00000000004004fe : mov %eax, -0x4 (%rbp) 0x0000000000400501 : mov -0x4 (%rbp), %eax 0x0000000000400504 : pop %rbp 0x0000000000400505 : retq End of assembler dump. Give a 1-2 sentence description of the purpose of each instruction. I am more interested in the why than the what.Explanation / Answer
INSTRUCTION
PURPOSE
Push %rsp
save the base pointer to the stack.
//%rbp is the base pointer, which points to the base of the current stack frame, the stack starts at a high memory address and grows downwards. %rsp is the stack pointer, which points to the top of the current stack frame, points to base pointer.
Mov %rsp,%rbp
put the current stack pointer into the base pointer.
Mov %edi,-0x14(%rdp)
Edi value has copies the value stored in the stack(rdp-14) (stack grows downward)
Mov –ox14(%rdp),%eax
%eax is a general purpose registers , move the content of the next value in stack eax register
Imul -0x14(%rdp),%eax
multiply the contents of rdp by the contents of the memory at location eax. Store the result in eax.(multiply the two values)
Mov %eax , -0x4(%rbp)
Result of multiplication in eax will be stored in stack at the pointer rbp(-4)
Mov -0x4(%rbp),%eax
Reallocating the values to eax
Pop %rdp
Remove the value from the stack
retq
return
INSTRUCTION
PURPOSE
Push %rsp
save the base pointer to the stack.
//%rbp is the base pointer, which points to the base of the current stack frame, the stack starts at a high memory address and grows downwards. %rsp is the stack pointer, which points to the top of the current stack frame, points to base pointer.
Mov %rsp,%rbp
put the current stack pointer into the base pointer.
Mov %edi,-0x14(%rdp)
Edi value has copies the value stored in the stack(rdp-14) (stack grows downward)
Mov –ox14(%rdp),%eax
%eax is a general purpose registers , move the content of the next value in stack eax register
Imul -0x14(%rdp),%eax
multiply the contents of rdp by the contents of the memory at location eax. Store the result in eax.(multiply the two values)
Mov %eax , -0x4(%rbp)
Result of multiplication in eax will be stored in stack at the pointer rbp(-4)
Mov -0x4(%rbp),%eax
Reallocating the values to eax
Pop %rdp
Remove the value from the stack
retq
return
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.