This preview shows pages 1–2. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.View Full Document
Unformatted text preview: CPSC 313, 05w Term 1— Midterm 1 — Solutions Date: October 7, 2005; Instructor: Mike Feeley 1. (10 marks) Short answers. 1a. What is the advantage of using two different registers (i.e., %ebp and %esp ) to store virtual addresses to the runtime stack? The stack pointer changes during the execution of a procedure when temporary values, registers or arguments are saved and restored. Keeping a separate base pointer that does not change during the execution of a procedure allows the compiler to access local variables and formal arguments using static offsets from the base pointer register that are the same everywhere in the procedure. 1b. What does a call instruction do that a jmp instruction does not? It saves the return address (i.e., the virtual address of the next instruction to execute after the procedure return statement executes) by pushing it on the stack before jumping to the called procedure. 1c. We discussed two ways to implement a C-language switch statement in assembly language. What are they? Under what conditions would one be favoured over the other (both ways)? The two methods are nested if-then-else statements and a jump table. Jump tables are faster when there are more than a few case bodies. If-then-else is preferred if there are just a few cases or if the case labels are sparse (i.e., the numeric difference between the largest and smallest case labels is much larger than the number of cases)....
View Full Document
This note was uploaded on 10/09/2011 for the course CPSC 344 taught by Professor Karen during the Fall '10 term at UBC.
- Fall '10