{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

cs313-2005-t1-midterm1-solution

cs313-2005-t1-midterm1-solution - CPSC 313 05w Term 1...

Info icon This preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
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).
Image of page 1

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern