Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

9. The following code cod for a c procedure: e sequence occurs near the beginnin

ID: 3586450 • Letter: 9

Question


9. The following code cod for a c procedure: e sequence occurs near the beginning of the assembly code generated by Ecc 5 Points 1. subq 2, movq 3. movq 4. movq 5. movq 6" movq 7, movq 8.movq 9.movq 10, movq $24, %rsp %rbx ,(%rsp) %r12, 8(%rsp) %r13 , 16(%rsp) 16(%rbp), %rbx 24 (%rbp), %r13 (%rbx), %r12 (%r13), %rax 16(%rbp ) ,%rdx (%rax), %rcx program modifies these and others. At the end of the procedure, the values of the registers %rbx, %r12, and %r13 are restored (those instructions are not shown) while the other registers are left in their modified states. Why are not all of the registers saved and restored? we see that just three registers (%rbx, %r12 and %r13) are saved on the stack in lines 2-4. The

Explanation / Answer

As we know a processor register  is one of a small set of data holding places that are part of the computer processor. A register may hold an instruction, a storage address, or any kind of data (such as a bit sequence or individual characters)

While executing any code, compilers make use of a bunch registers for faster operation such as RAX, RCX, RDX, R8, R9, R10, R11, RBX, RBP, RDI, RSI, R12, R13, R14, R15 etc.

The registers RAX, RCX, RDX, R8, R9, R10, R11 are considered volatile and must be considered destroyed on function calls.
Whereas the registers RBX, RBP, RDI, RSI, R12, R13, R14, and R15 are considered nonvolatile and must be saved and restored by a function that uses them because these belong to the calling function.

Hence in above example Registers %rbx , %r12 and %r13 “belong” to the calling function and the called function is required to preserve their values. In other words, a called function must preserve these registers’ values for its caller. Remaining registers “belong” to the called function and if a calling function wants to preserve such a register value across a function call, it must save the value in its local stack frame.