184k views
0 votes
Show the single MIPS machine (not pseudo!) instruction or minimal sequence of machine instructions for these pseudo instructions (question a and b) and C statements (questions c and d):

Pseudo instruction What it accomplishes
a.(3 points) flip $s6; # all bits of $s6 are flipped (0 becomes 1, 1 becomes 0)
b. (6 points) x[9] = x[6] + a;
Assume a is in register $13 and the array x begins at memory location 196,612 ten.
c.(4 points) if (i >= j) goto L;
Assume that variable i corresponds to register $s5 and variable j corresponds to register $s6.

User Howell
by
7.8k points

1 Answer

3 votes

Final answer:

The MIPS machine instruction for flipping all bits of $s6 is nor $s6, $s6, $s6. The minimal sequence of MIPS machine instructions for x[9] = x[6] + a is lw $t0, 196612($zero); addu $t1, $t0, $13; sw $t1, 196624($zero). The minimal sequence of MIPS machine instructions for if (i >= j) goto L is slt $t0, $s5, $s6; bnez $t0, L.

Step-by-step explanation:

Pseudo instruction a:
The MIPS machine instruction that accomplishes flipping all bits of $s6 is nor $s6, $s6, $s6. This instruction performs a bitwise NOR operation on $s6 with itself, effectively flipping all bits.

Pseudo instruction b:
The minimal sequence of MIPS machine instructions for x[9] = x[6] + a is:
lw $t0, 196612($zero) (load x[6] into $t0)
addu $t1, $t0, $13 (add $13 (a) to $t0)
sw $t1, 196624($zero) (store $t1 to x[9])

C statement c:
The minimal sequence of MIPS machine instructions for the if (i >= j) goto L statement is:
slt $t0, $s5, $s6 (set $t0 to 1 if i < j, 0 otherwise)
bnez $t0, L (branch to L if $t0 is not zero)

User Art Spasky
by
7.7k points