CS30 Quiz 3: Assembly Instructions for Local Variables and Arrays - Prof. Richard Ord, Quizzes of Computer Science

The assembly instructions for saving stack space for local variables and an array, as well as storing values into these variables in the cs30 course, fall 2001. It covers saving space for short, char, long, unsigned short, and int variables, as well as an array of char, and performing assignments using pointers.

Typology: Quizzes

2010/2011

Uploaded on 06/07/2011

koofers-user-40u
koofers-user-40u 🇺🇸

9 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Name:
cs30x____
Score:
Quiz 3
CSE 30
Fall 2001
#1.
a) Write the appropriate save instruction to allocate stack space for the following local variables and any
padding.
short a;
char b;
long c;
unsigned short d;
int e;
save _________ , ______________________________ , _________
(Use the formula, not an absolute value)
b) Write the appropriate instructions to store the value -4200 in local variable e as defined above (hint:
you cannot assign an immediate constant value directly to memory — you can only store from a register
to memory).
________________________ ! -4200 -> %l0
________________________ ! %l0 -> local variable e
c) Write the appropriate instructions to store the value 0x911 in local variable c as defined above (same
hint as above).
________________________ ! 0x911 -> %l0
________________________ ! %l0 -> local variable c
d) Write the appropriate instruction to place the value in local variable d into register %l0.
________________________ ! d -> %l0
e) Write the appropriate instruction to place the value in local variable a into register %l0.
________________________ ! a -> %l0
(OVER)
pf2

Partial preview of the text

Download CS30 Quiz 3: Assembly Instructions for Local Variables and Arrays - Prof. Richard Ord and more Quizzes Computer Science in PDF only on Docsity!

Name:

cs30x____

Score:

Quiz 3

CSE 30

Fall 2001

a) Write the appropriate save instruction to allocate stack space for the following local variables and any padding. short a; char b; long c; unsigned short d; int e; save _________ , ______________________________ , _________ (Use the formula, not an absolute value) b) Write the appropriate instructions to store the value -4200 in local variable e as defined above (hint: you cannot assign an immediate constant value directly to memory — you can only store from a register to memory). ________________________! -4200 -> %l ________________________! %l0 -> local variable e

c) Write the appropriate instructions to store the value 0x911 in local variable c as defined above (same hint as above). ________________________! 0x911 -> %l ________________________! %l0 -> local variable c

d) Write the appropriate instruction to place the value in local variable d into register %l. ________________________! d -> %l

e) Write the appropriate instruction to place the value in local variable a into register %l. ________________________! a -> %l

(OVER)

a) Write the appropriate save instruction to allocate stack space for the following local variable declara- tion. char a[9]; save _________ , ______________________________ , _________ (Use the formula, not an absolute value) b) Write the appropriate instructions to perform the following assignment statements, assuming variable i is mapped to %l0 and ptr is mapped to %l. char i; /* i mapped to %l0 */ i = a[4]; ________________________! a[4] -> %l a[2] = i; ________________________! %l0 -> a[2] char ptr; / ptr mapped to %l1 / ptr = &a[1]; ________________________! &a[1] -> %l ++ptr; / ptr mapped to %l1 */ ________________________! ++ptr ptr = i; / i mapped to %l0; ptr to %l1 */ ________________________! %l0 -> *ptr i = ptr; / i mapped to %l0; ptr to %l1 */ ________________________! *ptr -> %l