Welcome to Scribd, the world's digital library. Read, publish, and share books and documents. See more
Standard view
Full view
of .
0 of .
Results for:
P. 1
24-section-handout

# 24-section-handout

Ratings: (0)|Views: 21|Likes:

### Availability:

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];
R2 =.2 M[R1];
R3 = M[SP + 4];

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];
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];
R2 = R1 + 48;
// compute grace + 2 * sizeof(alley)
R3 = M[SP + 8];
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