SPARC Assembly Quiz: Memory Layout and Instruction Generation - Prof. Richard Ord, Quizzes of Computer Science

A quiz question for students in a cse 131b course focused on sparc assembly. The question requires students to show the memory layout of local variables and write sparc assembly instructions for a given operation. It also includes a task to optimize an existing sparc assembly code for the function 'foo'.

Typology: Quizzes

Pre 2010

Uploaded on 03/28/2010

koofers-user-sog
koofers-user-sog ๐Ÿ‡บ๐Ÿ‡ธ

10 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Login name _________________ Quiz 5 Name ______________________
CSE 131B
Signature ___________________ Winter 2003 Student ID __________________
1. Show the memory layout of the following local variables allocated on the runtime Stack taking into
consideration the SPARC data type memory alignment restrictions discussed in class. Fill bytes in memory
with the appropriate local variable name. For example, if local variable name p takes 4 bytes, you will have 4
p's in the appropriate memory locations. If the local variable is an array, use the name followed by the index
number. For example, some number of p0's, p1's, p2's, etc. Place an X in any bytes of padding.
char a; low memory
short b;
int c;
short d[3];
double e;
%fp โ€“โ€“โ€“โ€“โ€“โ€“โ€“โ€“โ€“> high memory
Write the SPARC assembly instructions that would be generated by the following instruction using the above
memory layout of the local variables. Make no assumptions about values already loaded into any registers. All
local variable accesses must access the local variable space allocated on the Stack. Just give a straightforward
suboptimal code generation to perform this operation. Hint: This should take 4 instructions.
c = 420420 + c;
________________________________
________________________________
________________________________
________________________________
pf2

Partial preview of the text

Download SPARC Assembly Quiz: Memory Layout and Instruction Generation - Prof. Richard Ord and more Quizzes Computer Science in PDF only on Docsity!

Login name _________________ Quiz 5 Name ______________________

CSE 131B

Signature ___________________ Winter 2003 Student ID __________________

1. Show the memory layout of the following local variables allocated on the runtime Stack taking into

consideration the SPARC data type memory alignment restrictions discussed in class. Fill bytes in memory

with the appropriate local variable name. For example, if local variable name p takes 4 bytes, you will have 4

p's in the appropriate memory locations. If the local variable is an array, use the name followed by the index

number. For example, some number of p0's, p1's, p2's, etc. Place an X in any bytes of padding.

char a; low memory

short b;

int c;

short d[3];

double e;

%fp โ€“โ€“โ€“โ€“โ€“โ€“โ€“โ€“โ€“> high memory

Write the SPARC assembly instructions that would be generated by the following instruction using the above

memory layout of the local variables. Make no assumptions about values already loaded into any registers. All

local variable accesses must access the local variable space allocated on the Stack. Just give a straightforward

suboptimal code generation to perform this operation. Hint: This should take 4 instructions.

c = 420420 + c;

________________________________

________________________________

________________________________

________________________________

2. Given the following code for foo(), write an equivalent more highly optimized version in SPARC assembly.

Assume: a is mapped to local register %l

b is mapped to local register %l c is mapped to local register %l x is a global variable allocated in the Data segment and NOT mapped to a register

Oberon SPARC Assembly VAR x : INTEGER; .global main, foo

PROCEDURE foo( i : INTEGER ); .section ".data" VAR a, b, c : INTEGER; .align 4 x: .word 0 BEGIN a := 15; .section ".text" b := a + 10; foo:! mapping local vars c := i + b; save %sp, -96, %sp! to local regs

x := c; mov 15, %l0! r0 = 15 a := x; add %l0, 10, %l1! r1 = r0 + 10 b := x; add %i0, %l1, %l2! r2 = param1 + r x := c; (* Other code may access a,b,c,x *) set x, %l3! x = r END foo; st %l2, [%l3] set x, %l3! r0 = x BEGIN ld [%l3], %l foo( 5 ); set x, %l3! r1 = x END. ld [%l3], %l set x, %l3! x = r st %l2, [%l3]

/* other code may access a,b,c,x */ ret restore

main: /* Code for main() not important */

Rewrite only code that is in the bounds of the rectangle.

What question would you most like to see on the Final?