CS30 Fall 2007 Quiz 4 - SPARC Architecture and C Programming - Prof. Richard Ord, Quizzes of Computer Science

A cs30 quiz from fall 2007, focusing on the sparc architecture and c programming concepts such as register usage, save instructions, local variable allocation, and function call mechanics.

Typology: Quizzes

Pre 2010

Uploaded on 03/28/2010

koofers-user-9pi
koofers-user-9pi 🇺🇸

10 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Student ID __________________
Name_______________
cs30x____
Signature ____________________
Score:
Quiz 4
CSE 30
Fall 2007
#1. On the SPARC architecture, ________________________ are accessed with a positive offset from %fp.
___________ instruction saves the current value of %pc in ___________.
___________ instruction adds ________ to the value %i7 and stores the result in %pc.
___________ do not guarantee their arguments will be evaluated only once.
___________ subroutine is a subroutine that uses save and restore instructions.
___________ instruction should never have a restore instruction in its delay slot.
___________ subroutine is a traditional subroutine that passes parameters on the stack.
Why is it a "bad thing" to return a pointer to a local variable or parameter?
#2. Write the appropriate save instruction to allocate stack space for the following local variable.
struct foo {
char a;
short b;
long c;
char d;
double e;
} fubar;
save
________ , ______________________________________, _________
(Use the formula, not an absolute value)
Write the appropriate unoptimized SPARC assembly instructions using the above local variable.
fubar.b = fubar.c; fubar.d = fubar.a;
(over)
pf2

Partial preview of the text

Download CS30 Fall 2007 Quiz 4 - SPARC Architecture and C Programming - Prof. Richard Ord and more Quizzes Computer Science in PDF only on Docsity!

Student ID __________________ Name_______________

cs30x____

Signature ____________________ Score:

Quiz 4

CSE 30

Fall 2007

#1. On the SPARC architecture, ________________________ are accessed with a positive offset from %fp.

___________ instruction saves the current value of %pc in ___________.

___________ instruction adds ________ to the value %i7 and stores the result in %pc.

___________ do not guarantee their arguments will be evaluated only once.

___________ subroutine is a subroutine that uses save and restore instructions.

___________ instruction should never have a restore instruction in its delay slot.

___________ subroutine is a traditional subroutine that passes parameters on the stack.

Why is it a "bad thing" to return a pointer to a local variable or parameter?

#2. Write the appropriate save instruction to allocate stack space for the following local variable.

struct foo { char a; short b; long c; char d; double e; } fubar;

save ________ , ______________________________________, _________

(Use the formula, not an absolute value)

Write the appropriate unoptimized SPARC assembly instructions using the above local variable.

fubar.b = fubar.c; fubar.d = fubar.a;

(over)

#3. Given

int a; void fubar( int x ) { int y = -42; static int *z = &a; ... }

When this function is called, identify which area of the C Runtime Environment each of the following will be

allocated.

Area of Runtime Env. Scope/Visibility

x ____________ ___________

y ____________ ___________

z ____________ ___________

fubar ____________ ___________

where z

is pointing ____________

If the function above is called 4 times, indicate how many times will y be initialized to -42? _________

#4. What gets printed with the function call mystery( 5 );?

int mystery( int param ) { int local = 45;

if ( local > param ) { local = local - param; printf( "%d\n", local ); /* Output the value of local followed by a newline / param = mystery( param + 10 ) + local; printf( "%d\n", param ); / Output the value of param followed by a newline */ } else { printf( "Whoa\n" ); }

return local; }

Put answer here