EE108B
Winter 2003-2004
Handout #20
EE108b – Solution to Problem Set #2 (Total 56 points)
Due Tues Feb 3, 5 PM in Gates 408 – No Late Day
1.
(Total 11 points)
The following C program is compiled into MIPS objects with no optimization and
with –O2 optimization.
int A[100], B[100];
main() {
int i;
int c = 10;
for (i=0; i < 100; i++)
A[i] = B[i] + c;
}
Unoptimized Code
Optimized with –O2
0x0: lui
gp,
0
0x4: addiu
gp,
gp,
0
0x8: addu
gp,
gp,
t9
0xc: addiu
sp,
sp,
-24
0x10: sw
gp,
0(sp)
0x14: sw
fp,
20(sp)
0x18: sw
gp,
16(sp)
0x1c: move
fp,
sp
0x20: li
v0,
10
0x24: sw
v0,
12(fp)
0x28: sw
zero, 8(fp)
0x2c: lw
v0,
8(fp)
0x30: slti
v1,
v0,
100
0x34: bne
v1,
zero,
0x3c
0x38: b
0x88
0x3c: lw
v0,
8(fp)
0x40: move
v1,
v0
0x44: sll
v0,
v1,
2
0x48: lw
v1,
0(gp)
0x4c: addu
v0,
v0,
v1
0x50: lw
v1,
8(fp)
0x54: move
a0,
v1
0x58: sll
v1,
a0,
2
0x5c: lw
a0,
0(gp)
0x60: addu
v1,
v1,
a0
0x64: lw
a0,
0(v1)
0x68: lw
v1,
12(fp)
0x6c: addu
a0,
a0,
v1
0x70: sw
a0,
0(v0)
0x74: lw
v1,
8(fp)
0x78: addiu
v0,
v1,
1
0x7c: move
v1,
v0
0x80: sw
v1,
8(fp)
0x0:
lui
gp, 0
0x4:
addiu
gp, gp,
0
0x8:
addu
gp, gp,
t9
0xc:
li
a2, 10
0x10: move
a1, zero
0x14: lw
a0, 0(gp)
0x18: lw
v1, 0(gp)
0x1c: lw
v0, 0(v1)
0x20: addiu
v1, v1,
4
0x24: addiu
a1, a1,
1
0x28: addu
v0, v0,
a2
0x2c: sw
v0, 0(a0)
0x30: slti
v0, a1,
100
0x34: addiu
a0, a0,
4
0x38: bne
v0, zero, 0x1c
0x3c: jr
ra
1