Professional Documents
Culture Documents
B[8] = A[i-j];
3) For the MIPS assembly instructions in Exercise 2, rewrite the assembly code
to minimize the number if MIPS instructions (if possible) needed to carry out
the same function.
sll $t0, $s0, 2 // $t0 = f * 4;
add $t0, $s6, $t0 // $t0 = &A[f];
sll $t1, $s1, 2 // $t1 = g * 4;
add $t1, $s7, $t1 // $t1 = &B[g];
lw $s0, 0($t0) // f = A[f];
addi $t2, $t0, 4 // $t2 = &A[f + 1] Simplify this instruction
lw $t0, 4($t0) // $t0 = A[f + 1]; Change by this line
add $t0, $t0, $s0 // $t0 = $t0 + f = A[f + 1] + A[f];
sw $t0, 0($t1) // B[g] = $t0 = A[f + 1] + A[f];
Instructions Format OP RS RT RD IM
addi $t0, $s6, 4 I-type 8 22 8 - 4
add $t1, $s6, $0 R-type 32 22 0 9 -
sw $t1, 0($t0) I-type 43 8 9 - 0
lw $t0, 0($t0) I-type 35 8 8 - 0
add $s0, $t1, $t0 R-type 32 9 8 16 -
00011010010000000000000000000011
blez $t4,3
00100000000000000000000000000000
addi $zero, $zero, 0
10101110001010110000000000000000
sw $t2, $t5, 0
10101110001010100000000000000010
sw $t2, $t4, 2
00100001001010010000000000001000
addi $t1, $t1, 8
7) Pseudo-instructions are not part of the MIPS instruction set but often appear
in MIPS programs. The assembler then has to convert them into a small set
of real MIPS instructions. For each of the following pseudo-instructions,
convert them to a very short equivalent sequence of real MIPS instructions.
If you need a temporary register, you should use $at.
Note that “small” is a constant that fits in 16 bits (i.e. small enough for the
immediate field of an instruction), and “big” is a constant that is 32 bits (i.e.
too long for the immediate field)
8) Assume that we would like to expand the MIPS register fi le to 128 registers
and expand the instruction set to contain four times as many instructions.
a. How this would this affect the size of each of the bit fields in the R-type
instructions?
b. How this would this affect the size of each of the bit fields in
the I-type instructions?
_____________________________-
a. Expanding the register file to 128 bits adds 2 bits to rs, rt, and rd,
increasing them to 7 bits each. Assuming 4x (=22) the instructions
expands the opcode by 2 bits, to 8 bits total.
b. 2 bit , each add to rs, rt and the opcode
9) Find the shortest sequence of MIPS instructions that extracts bits 16 down to
11 from register $t0 and uses the value of this field to replace bits 31 down
to 26 in register $t1 without changing the other 26 bits of register $t1.
srl $t2, $t0, 10
sll $t2, $t2, 26
srl $t1, $t1, 6
srl $t1, $t1, 6
add $t2, $t2, $t1
The end