Transcript MIPS - Wiki

CS 300 – Lecture 6
Intro to Computer Architecture
/ Assembly Language
Instructions
Homework 3
Questions????
The lw and sw instructions
lw
r1, offset(r2)
Load register r1 with the memory word at
the location determined by adding the
contents of r2 to the offset
lw $r1,8($r2)
The "sw" instruction moves data from
register to memory:
sw r1, offset(r2)
Byte Addressable Memories
In a MIPS, each word is divided into 4 bytes.
Each byte has its own address.
Words MUST be aligned: that is, the lower 2
bits must be 00.
Remember that memory is just a BIG array
– we need to partition this specific program
level structures.
Constants
Constants come from two places:
* The memory: values that are "pre-loaded"
when the program starts and available as
needed.
* The instruction stream: small constants
can be embedded directly into instructions
The "addi" instruction
addi r1, r2, c
Here, "c" is a constant that is added to r2
r1 = r2 + c
The range of the constant is determined by the
instruction format.
Note that "lw" and "sw" also used constants
embedded in the instruction.
Encoding MIPS Instructions
Registers (32): 5 bits
op
(6)
Op Code
add, sub
rs
(5)
rt
(5)
rd
(5)
shamt funct
(5)
(6)
Shift Amount
(not used yet)
Function code
Encoding MIPS Instructions
Registers (32): 5 bits
op
(6)
rs
(5)
rt
(5)
Op Code: addi, lw, sw
Constant
(16)
Digression: 2's Complement
How do we represent negative numbers?
To negate: complement and add 1
So: -1 = 11111111111 (all 1's)
Let's look at some examples
Getting the Binary
We need to understand the encoding of
each field to determine the overall
instruction encoding.
The register encoding is given in the book
Op codes are usually given in a table
Constants are binary numbers