Welcome to Scribd, the world's digital library. Read, publish, and share books and documents. See more
Download
Standard view
Full view
of .
Save to My Library
Look up keyword
Like this
2Activity
0 of .
Results for:
No results containing your search query
P. 1
24-section-handout

24-section-handout

Ratings: (0)|Views: 345|Likes:
Published by minhhai2209

More info:

Published by: minhhai2209 on Feb 18, 2009
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as PDF, TXT or read online from Scribd
See more
See less

05/10/2014

pdf

text

original

CS107
Handout 24S
Spring 2008
May 6, 2008
Section Solution
Solution 1: South Of Market
Consider the followings t r u c t definitions:

typedef struct alley {
char clementina[4];
short **minna[3];
struct alley *jessie;
int clara;

} alley;
char *washburn(alley *grace, short *bernice)

{
grace[2].clementina[12] = *bernice;
((alley *)(grace->minna))->jessie[2].clara += 960;
return *(char **)washburn(grace + 2, &bernice[2]);

}
Generate code for the entirew a s h b u r n function. Be clear about
what assembly code corresponds to what line.
// grace[2].clementina[12] = *bernice;
R1 = M[SP + 8];
// load bernice
R2 =.2 M[R1];
// load *bernice
R3 = M[SP + 4];

// load grace
M[R3 + 60] =.1 R2 // assign char at R3 + 2 * sizeof(alley) + 12 to be
*Bernice

// ((alley *)(grace->minna))->jessie[2].clara += 960;
R1 = M[SP + 4];
// load grace
R2 = R1 + 4;

// compute grace->minna (oh, that\u2019s an alley *)
R3 = M[R2 + 16]; // load jessie field of pretend struct
R4 = M[R3 + 68]; // load old value of int at R3 + 3 * sizeof(alley) \u2013
sizeof(int)
R5 = R4 + 960;

// compute new value within register
M[R3 + 68] = R5; // flush new value over old value
// return *(char **)washburn(grace + 2, &bernice[2]);
R1 = M[SP + 4];
// load grace
R2 = R1 + 48;
// compute grace + 2 * sizeof(alley)
R3 = M[SP + 8];
// load Bernice
R4 = R1 + 4;
// compute &bernice[2]
SP = SP \u2013 8;

// make space for parameters
M[SP] = R2;
M[SP + 4] = R4;
CALL <washburn>;
SP = SP + 8;

// clean up params
RV = M[RV];
// update return value (note dereference)
RET;
line 1
line 2
line 3
grace
bernice

You're Reading a Free Preview

Download
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->