- Simplicity favors regularity
- Smaller is faster
- Make the common case fast
Addressing Memory Location
- Each word is 4 bytes
A[] : base address (e.g. 0x20)
A[1] : (e.g. 0x24)
distance between 0 and 1 is called offset
A[i] has i elements in front of it, offset will be i x (size of each element)
To get Ai, Ai = base address + i x (size of each element)
Address Space
A memory with n-bit address has max capacity of bytes (each address assigned to one byte)
Endianness
- Big-Endian (normal)
- end of word matches big address
- Little-Endian (reversed)
- end of word matches little address
For conversion, we reverse with a step of 8 bits (2 hex)
Registers

$zero- constant zero
- read-only
Operators
la- Load address
- Can also load address of label
lw- Moves data from memory to a register
sw- Store moves data from a register to memory
add,addi- Add
sub- Subtract
$s0 = $s1 - $s2
- Subtract
and,andi- Bit-wise and
or,ori- Bit-wise or
nor- Bit-wise nor
sll,srl- Shift to left/right by gives the original multiply by /
- Fill emptied its with 0s
- Truncate when overflow
beq,bnebeq/bne reg1, reg2, L1- Go to statement labeled
L1ifreg1andreg2are equal/not equal - Go to only skips until the statement
bgez,bgtz,blez,bltz- Greater than or equal to zero
- Greater than zero
- Less than or equal to zero
- Less than zero
jj L1- Always go to statement labeled
L1
jr- Jump register
- Each instruction is 4 bytes long
- Can be used to jump instructions
operations with immediate operand are suffixed with
i

Execution Time
Constant > Register > Memory
Loops
If Statement
p.39
Instruction Formats
- R-type (register)
- I-type (immediate)
- J-type (jump)
Preserve on Call

Array Addressing
- Load address of array with label
arrto$s0 - Set index to address in
$t0 - Multiply index by 4, or other data sizes
- 4 bytes for .word
- 2 bytes for .half
- 1 byte for .byte
- Add index to base address to obtain the actual address
- Load word from the zeroth index
la $s0, arr # $s0 = &arr[0]
add $t0, 1, $zero # $t0 = 1
sll $t0, $t0, 2 # $t0 = ind * 4
add $t0, $t0, $s0 # $t0 = $t0 + &arr[0]
lw $t0, 0($t0) # $t0 = A[$t0]
Branching
slti $t1, $a0, 1 # num < 1
bne $t1, $zero, ExitOuterLoop # if num <= 0

https://matthews.sites.truman.edu/files/2019/11/pseudoinstructions.pdfj
Load Upper
# 0000 0000 0011 1101 0000 1001 0000 00002 (0x003D0900)
lui $s0, 61
ori $s0, $s0, 2304
Addressing
PC Relative
- I-type instruction only have 16 bits address
- Add branch offset (number of words) to PC+4
- Can jump within words before/after
Pesudo-direct Addressing
- J-type used by
jorjal - 6 bits op, 26 bits address

jump even further with
jrby storing the address in register