Section Exercises

True or False:

chevron-rightThe content of a callee-saved register does not remain the same after a subroutine is called.hashtag

False!

The value of a callee-saved registered is saved by the subroutine that is called. So if in a callee-saved register, we have a value x and then we call a subroutine foo, even though we use the callee saved register in the execution of foo, when the subroutine returns, the callee-saved register still has the value x.

chevron-rightThe value of a caller-saved register remains the same after a subroutine is called.hashtag

False!

The value of a caller-saved register can be changed by a subroutine call, so, in order to reuse the initial value of such a register, you need to store it either on the stack or in a callee-saved register.

chevron-rightrbx, rsp, and rbp are callee-saved registers.hashtag

True!

chevron-rightrax is a callee-saved register.hashtag

False!

rax is a caller-saved register, so its value has to be stored somewhere else.

Hint: remember that the value returned by a subroutine will be found in rax. meaning that the content of rax is overwritten with every subroutine execution.

chevron-rightrdi, rsi, rdx, and rcx are caller-saved registers.hashtag

True!

chevron-rightStack (mis)alignment was the most common cause of a subroutine call crash in Computer Organization 2024.hashtag

True!

Keep in mind that before calling a subroutine, your stack should be 16-byte aligned.

chevron-rightThe term stack frame refers to the entire stack.hashtag

False!

The stack frame refers to the area of the stack that is used by a subroutine.

chevron-rightrsp is indicates the base of the current stack frame.hashtag

False!

rsp, the stack pointer, indicates the top of the current stack frame and it moves with every push or pop instruction. rbp is the base pointer which indicates the base of the current stack frame.

chevron-rightA prolog is used to set up the stack frame of a subroutine.hashtag

True!

chevron-rightThe epilog refers to the action of restoring the previous stack frame before a subroutine returns.hashtag

True!

chevron-rightIt is advised to store local variables in registers.hashtag

False!

Although, in theory, you could, it is not advisable because storing the local variables in registers has some drawbacks such as limiting the number of local variables (there is a limited number of registers, hence a limited number of local variables) and you risk to have their value changed if the register is used in a subroutine.

chevron-rightTo make space for the local values, you can push them on the stack after the prologue.hashtag

True!

As an alternative, you can subtract the needed space from the stack pointer if the local variables are uninitialized.

Multiple Choice

Why is it or is it not the stack misaligned in the following cases?

Last updated