Subroutine arguments are passed on the stack, and can be accessed within the bod
ID: 3679095 • Letter: S
Question
Subroutine arguments are passed on the stack, and can be accessed within the body of the subroutine starting at address EBP+8. At the start of each subroutine: Save EBP on the stack Copy the current value of the stack pointer (ESP) to EBP Create space within the stack for each local variable by subtracting the appropriate value from ESP. For example, if your function uses four integer local variables, each of which contains four bytes, subtract 16 from ESP. Local variables can then be accessed starting at the address EBP-4. A subroutine's return value is typically stored in EAX. See Lectures 14 and 16-18 for more details on subroutines, the x 86 architecture, and the conversion from high-level concepts to low-level assembly.Explanation / Answer
The X86 assembly routine for a given subroutine function:
f(int, int, int):
pushq %rbp
movq %rsp, %rbp
pushq %rbx
movl %edi, -28(%rbp)
movl %esi, -32(%rbp)
movl %edx, -36(%rbp)
movl -32(%rbp), %eax
movl -28(%rbp), %edx
leal (%rdx,%rax), %eax
movl %eax, -12(%rbp)
movl -36(%rbp), %eax
movl -12(%rbp), %edx
leal (%rdx,%rax), %ecx
movl -36(%rbp), %eax
movl -12(%rbp), %edx
movl %edx, %ebx
subl %eax, %ebx
movl %ebx, %eax
imull %ecx, %eax
popq %rbx
leave
ret
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.