hw2 - arguments to h must be passed in r1 and r2, then x...

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

View Full Document Right Arrow Icon
Homework 2 Due in class Wednesday November 16th 1. Using the C compiler ( gcc ) installed on the lab machines, compile some small test functions into assembly language ( gcc -S ). Turn on optimizations ( gcc -O -S ). Then evaluate the compiled programs by these criteria: i. Are local variables kept in registers? ii. If local variable b is live across more that one procedure call, is it kept in a callee-save register? Explain how doing this would speed up the following program: void g(void); void h(int); int f(int a) { int b = a+1; g(); h(b); return b+2; } iii.If local variable x is never live across a procedure call, is it properly kept in a caller-save register? Explain how doing this would speed up the following program: void f(int); void h(int y) { int x = y+1; f(y); f(2); } Generate assembly language for this program: void h(int, int); void m(int x, int y) { h(y,y); h(x,x); } Clearly, if arguments to m(x,y) arrive in registers r1 and r2, and
Background image of page 1

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

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

Unformatted text preview: arguments to h must be passed in r1 and r2, then x cannot stay in r1 during the marshaling of arguments to h(y,y). Explain when and how the C compiler moves x out of r1 so as to call h(y,y). iv.For each of the variables a, b, c, d, e in the following C program, say whether the compiler allocates it in memory or a register, and why. int g(int, int *); int f(int a, int b) { int c[3], d, e; d = a+1; e = g(c, &b); return e+c[1]+b; } v. Compile the following program to assembly language: int leaf(int a, int b, int c, int d, int e, int f, int g, int h) { return a+b+c+d+e+f+g+h; } int foo(void); int nonleaf (int a, int b, int c, int d, int e, int f, int g, int h) { int x = foo(); return a + b + c + d + e + f + g + h + x; } Then identify all the components of the calling sequence and explain what each line of assembly language does (including the pseudo-instructions)....
View Full Document

Page1 / 2

hw2 - arguments to h must be passed in r1 and r2, then x...

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