diff --git a/Instruction-Set.md b/Instruction-Set.md index d62171f..dc72faa 100644 --- a/Instruction-Set.md +++ b/Instruction-Set.md @@ -13,10 +13,42 @@ Also note that immediate (constant/literal) arguments are 16-bits long in I (imm +### R-type Instruction Encoding + +| Bits 31-26 | Bits 25-21 | Bits 20-16 | Bits 15-11 | Bits 10-6 | Bits 5-0 | +| - | - | - | - | - | - | +| Opcode | Source Reg 1 | Source Reg 2 | Destination Reg | Shift Amount | Unused | + + +The shift amount must be 0 when the opcode does not match a shift instruction or else the CPU will assert an Illegal Instruction exception. + +If any register field is not used, it should be set to the special value NOREG, defined in the Registers section of this document. Failure to do so may result in an Illegal Instruction exception as this is undefined for an instruction that does not expect this argument to be provided. + +### I-type Instruction Encoding + +| Bits 31-26 | Bits 25-21 | Bits 20-16 | Bits 15-0 | +| - | - | - | - | +| Opcode | Source Reg | Dest Reg | 16-bit immediate | +I-type instructions are used when 16-bit immediate arguments are desired. This could be for +immediate arithmetic instructions (like adding 10 to the value in ACC), or loads and stores, where we may want to access the ith index of an array using an offset. +### J-type Instruction Encoding +| Bits 31-26 | Bits 25-0 | +| - | - | +| Opcode | Address | + +J-type instructions are used for absolute jumps. + +The 26-bit address is converted to a 32-bit address by: +The 26-bit address field is shifted left by 2 bits (due to word alignment we ignore the 2 least significant bits). +Combined with the upper 4 bits of the PC to form a 32-bit address (bitwise OR). + +The jump range: 256MB region around current PC. For longer jumps than this, see jr (Jump to word address in register). + +To compute this address, the linker should find the address of the label, cut off the top 4 bits, then rightward shift twice. The CPU will then convert this to the actual 32-bit address following the steps outlined above. ### Load/Store and Data Movement Instructions