{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

21S-Section-Solution

# 21S-Section-Solution - CS107 Spring 2007 Handou t 21S...

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

CS107 Handout 21S Spring 2007 May 4, 2007 Section Solution Problem 1: The Incredibles Consider the following struct definition: typedef struct { int violet; char *dash[2]; char superboy[4]; } superhero; static superhero **pixar(superhero *syndrome); static superhero *theincredibles(short *frozone, superhero elastigirl) { frozone += elastigirl.superboy[*frozone]; ((superhero *)((superhero *) elastigirl.dash[0])->dash)->violet = 400; return *pixar(&elastigirl) + 10; } Generate code for the entire theincredibles function. Be clear about what assembly code corresponds to what line. // line 1 R1 = M[SP + 4]; // R1 stores frozone R2 =.2 M[R1]; // R2 stores *frozone R3 = SP + 20; // R3 stores &elastigirl.superboy[0] R4 = R3 + R2; // R4 stores &elastigirl.superboy[R2] R5 =.1 M[R4]; // R5 stores elastigirl.superboy[R2] R6 = R5 * 2; // scale rhs by sizeof(short) R7 = R1 + R6; // compute result M[SP + 4] = R7; // store result back to frozone // line 2 R1 = M[SP + 12]; // load elastigirl.dash[0]; M[R1 + 4] = 400; // load 400 into the violet field of the struct we // pretend starts at R1 + 4 (&dash[0] is 4 bytes above // bottom of struct) // line 3 R1 = SP + 8; // prepare argument

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}