Skip to content

Middle Checklist

Since this is a long topic, it is good to have an intermediate checklist. So far, we have discussed basic arithmetic and logical instructions as well as their immediate variants (if any). The summary is shown below:

Basic

Operation Opcode MipC
Addition add $rd, $rs, $rt $rd = $rs + $rt
Subtraction sub $rd, $rs, $rt $rd = $rs - $rt
Shift Left Logical sll $rd, $rt, C5 $rd = $rt << C5
Shift Right Logical add $rd, $rt, C5 $rd = $rt >> C5
Bitwise AND and $rd, $rs, $rt $rd = $rs & $rt
Bitwise OR or $rd, $rs, $rt $rd = $rs | $rt
Bitwise XOR xor $rd, $rs, $rt $rd = $rs ^ $rt
Bitwise NOR nor $rd, $rs, $rt currently unavailable

Shift

Note that the second operand is $rt instead of $rs. Additionally, C5 is basically 5-bits unsigned integer. Why only 5-bits? Well, 25 = 32. If we shift left/right 32-bits, we get all 0. So any number greater than 32 is immaterial.

Immediate

Operation Opcode MipC
Addition addi $rt, $rs, C162s $rt = $rs + C162s
Bitwise AND andi $rt, $rs, C16 $rt = $rs & C16
Bitwise OR ori $rt, $rs, C16 $rt = $rs | C16
Bitwise XOR xori $rt, $rs, C16 $rt = $rs ^ C16

Note how the destination register (i.e., $rd) is now changed to target register (i.e., $rt).

Arithmetic

C162s is 16-bits 2s complement (i.e., signed integer). The range is from -215 to 215-1. These values are sign-extended. In other words, we extend it from 16-bits to 32-bits by duplicating the most significant bit (MSB). If the MSB is 0, we append 0 to the front. If the MSB is 1, we append 1 to the front.

Logical

C16 is 16-bits unsigned integer. The range is from 0 to 216-1. However, they are typically given as 16-bit patterns (i.e., 0xAAAA) instead. These values are bit-extended. In other words, we extend it from 16-bits to 32-bits by appending 0.