What C code performs the same computation as the following assembly code:
ld $a, r0
ld (r0), r1
ld $-10, r2
add r1, r2
bgt r2, L0
ld $0, r1
br L1
L0: ld $1, r1
br L1
L1: st r1, (r0)
if(a <= 0) a = 1;
else a = 0;
if(a <= 10) a = 1;
else a = 0;
if(a > 0) a = 1;
else a = 0;
if(a > 10) a = 1;
else a = 0;
Indicate below which piece of C code performs the same computation as the following assembly code. You will note that this code uses r1 without initializing it.
This is intentional. Your answer must work for all possible initial values of r1.
ld $a, r0
ld $0, r2
L0: ld (r0, r1, 4), r4
inc r1
add r4, r2
ld $s, r4
st r2, (r4)
ld $i, r4
st r1, (r4)
ld $-10, r3
add r1, r3
beq r3, L1
br L0
L1: halt
s = 0;
while (i != 10) {
i += 1;
s += a[i];
}
s = 0;
while (i != 10) {
s += a[i];
i += 1;
}
s = 0;
do {
i += 1;
s += a[i];
} while (i != 10)
s = 0;
do {
s += a[i];
i += 1;
} while (i != 10)