

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
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
1 / 2
This page cannot be seen from the preview
Don't miss anything!


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?