21S-Section-Solution

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

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

View Full Document Right Arrow Icon
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
Background image of page 1

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

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 01/14/2010 for the course CS 107 taught by Professor Cain,g during the Spring '08 term at Stanford.

Page1 / 3

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

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online