ori      $8, $0, 0x6F       # put bit pattern register into $8
        sll      $8, $8, 2          # shift left logical by two

A good answer might be:

Yes, this is OK.

Shifting in Place

When an ALU operation is performed: (1) data is copied from the register(s) into the ALU. Then (2), the ALU does the operation. Next (3) the result is written to the designated result register. There is no problem when an operand register is also the result register because the operand data was transferred to the ALU in the first step, leaving the register open to receive the result.

Sending the result back to the source register is called shifting in place. This phrase is misleading because actually the shift is done in the ALU and the register gets the result. Here is the machine instruction corresponding to the sll in the program:

   0    0    0    8    4    8    8    0    -- machine instruction in hex

0000 0000 0000 1000 0100 1000 1000 0000    -- machine instruction in bits

000000 00000  01000 01000  00010 000000    -- fields of the instruction

opcode ----- source dest   shft  2ndary    -- meaning of the fields

ALUop          $8    $8     2    sll

The sll operation is designated by the 6-bit zero at the beginning of the instruction and the 6-bit zero at the end. The remaining fields give the source register ($8 in this case), the destination register ($8 in this case), and the number of positions to shift (2 in this case).

The five zero bits after the opcode are not used. All MIPS instructions are 32 bits. These bits are arbitrarily given the value zero.


QUESTION 4:

Study the above instruction. Write the instruction for shift-left-logical the pattern in $0 by zero positions and leave the result in $0:

sll      $0, $0, 0          # fun machine instruction

Hint: on the midterm I expect you to write the 32-bit pattern for this instruction without hesitation! Memorize it now!