cs313-2006-t1-midterm1-solution

cs313-2006-t1-midterm1-solution - CPSC 313, 06w Term 1...

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: CPSC 313, 06w Term 1 Midterm 1 Solutions Date: October 4, 2006; Instructor: Norm Hutchinson 1. (8 marks) Short answers. 1a. (2 marks) Is the address of a local variable in a C function determined statically or dynamically ? Briefly explain. It is determined dynamically , as it is allocated on the stack. 1b. (2 marks) Is the code address to which a procedure returns when it exits determined statically or dynamically ? Briefly explain. It is dynamically determined when the procedure is called during execution of the program, by pushing the return address on the stack. 1c. (2 marks) Does the IA32 instruction-set architecture require that %esp be used as the stack pointer? Briefly explain. It does require it. The call and ret instructions implicitly refer to the %esp register and there are no reasonable alternatives that compiled code can use if chooses to use a different register to point to the stack. 1d. (2 marks) Give assembly-language code that computes %eax = %eax * 9 + 7 as efficiently as possible. leal 7(%eax,%eax,8), %eax # eax = eax * 9 + 7 2. (8 marks) Consider the following C source file. / * global variables * / int g, * gp, ** gpp; void foo (int * a1, int a2) { int l; / * consider each statement as if it were here * / } Give an assembly-code implementation of each of the following statements of function foo() . Consider each statement in isolation (i.e., as if it were the only statement of foo). Do not assume that variables start out in registers. Be sure to write results to the appropriate location in memory. Assume that the local variable l...
View Full Document

Page1 / 5

cs313-2006-t1-midterm1-solution - CPSC 313, 06w Term 1...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online