1

I'd like to figure out how to encode BASIC INSTRUCTION FORMATS referred to in the MIPS Green Sheet e.g. I'd like to encode the instruction add $t0 $t1, $t2.

I know that the Format is R; opcode will be 0x0; The Funct 0x20.

But how will I get the code for rs, rt, rd and shamt?

Mihai Chelaru
  • 7,614
  • 14
  • 45
  • 51

1 Answers1

0

The link in the question is mangled. It should be https://inst.eecs.berkeley.edu/~cs61c/resources/MIPS_Green_Sheet.pdf

If you look in the REGISTER NAME, NUMBER, USE, CALL CONVENTION box at the bottom right of page 1 of that PDF, you'll see that the registers with names $t0 through $t7 correspond to the registers numbered 8 through 15. For the instruction you're interested in:

    add $t0, $t1, $t2

$t0 is the destination register, specified by the rd field in the instruction. Since $t0 is register number 8, put 01000 into the rd field.

$t1 and $t2 are the source registers, specified by the rs and rt fields in the instruction. Since $t1 is register number 9 and $t2 is register number 10, put 01001 into the rs field and put 01010 into the rt field.

shamt is not used in the add instruction, so fill that field with zeroes.

BTW, that Green Sheet is fine as a reminder of the nitty-gritty details of the instruction set, but something like https://www.cs.ucsb.edu/~franklin/64/lectures/mipsassemblytutorial.pdf will be more helpful if you're just getting started with the MIPS architecture.

ottomeister
  • 5,415
  • 2
  • 23
  • 27