CS3350B Computer Architecture MIPS Introduction: Marc Moreno Maza
CS3350B Computer Architecture MIPS Introduction: Marc Moreno Maza
MIPS Introduction
▸ Levels of representation
Instructions: Language of the Computer
Instruction Set
▸ C code:
f = (g + h) - (i + j);
▸ Compiled MIPS code:
add t0, g, h # temp t0 = g + h
add t1, i, j # temp t1 = i + j
sub f, t0, t1 # f = t0 - t1
Register Operands
▸ C code:
f = (g + h) - (i + j);
▸ f, ..., j in $s0, ..., $s4
▸ Compiled MIPS code:
add $t0, $s1, $s2
add $t1, $s3, $s4
sub $s0, $t0, $t1
Memory operands
▸ Main memory used for storing composite data:
▸ Arrays, structures, dynamic data
▸ To apply an arithmetic operation, we need to
▸ load values from memory into registers, and
▸ store the result from register to memory
▸ Memory is byte addressable
▸ Each address identifies a word (= 4 bytes = 32 bits)
▸ each word is aligned in memory, that is,
▸ its address must be a multiple of 4
▸ MIPS is Big Endian
▸ that is, it stores the most significant byte in the smallest
address,
▸ in contrast, with little endian, the least-significant byte
is at the smallest address.
▸ Read https://en.wikipedia.org/wiki/Endianness
Memory operand example 1
▸ C code:
g = h + A[8];
▸ assume g in $s1, h in $s2, and the base address of A in
$s3
▸ Compiled MIPS code:
▸ With 4 bytes per word, the index 8 requires an offset of
32
lw $t0, 32($s3) # load word
add $s1, $s2, $t0
Memory Operand example 2
▸ C code:
A[12] = h + A[8];
▸ h in $s2, base address of A in $s3
▸ Compiled MIPS code:
lw $t0, 32($s3) # load word
add $t0, $s2, $t0
sw $t0, 48($s3) # store word
Registers vs. memory
▸ Range: 0 to + 2n – 1
▸ Example