Beruflich Dokumente
Kultur Dokumente
Advantages
Typical of Modern RISC Instruction sets Free Simulator Available for Unix, PCs and Macs Used in real machines - MIPS R2000 Processors Used in many CS Compiler Classes as Target Machine
MIPS Architecture
32-bit RISC Processor 32 32-bit Registers, $0..$31 Pipelined Execution of Instructions All instructions are 32-bits Most Instructions executed in one clock cycle 230 32-bit memory words Byte addressable memory
A 32-bit word contains four bytes To address the next word of memory add 4
OP
RS
RT
Address/Immediate
OP
Jump Address
PC relative - Address from instruction is added to the current value in the Program Counter
Example J 4 - Jumps to address PC+4 Saves address bits in jump instructions
SUB $1,$2,$3
Register 1 = Register 2 - Register 3
AND $1,$2,$3
Register 1 = Register 2 AND Register 3
ADDI $1,$2,10
Register 1 = Register 2 + 10
SW $1,100
Contents of memory location 100 = Register 1 Used to save registers
LUI $1,100
Register 1 upper 16-bits = 100 Lower 16-bits are set to all 0s Used to load a constant in the upper 16-bits Other constants in instructions are only 16-bits, so this instruction is used when a constant larger than 16-bits is required for the operation
JAL 100
Save PC in $31 and Jumps to PC+100 Used for subroutine calls
JR $31
Jumps to address in register 31 Used for subroutine returns
MIPS Labels
Instead of absolute memory addresses symbolic labels are used to indicate memory addresses in assembly language Assembly Language Programs are easier to modify and are easier to understand when labels are used
Examples Variable X is stored a location 123 in memory - Use label X instead of 123 in programs. Location LOOP_TOP is address 250 in a program - Use label LOOP_TOP instead of jump address 250 in programs
LOOP:
ADD $a0,$a0,$a1
Sets up LOOP as a Label that points to the Add instruction Can jump to LOOP (i.e. J LOOP)
.WORD
Reserve a 32-bit word in memory for a variable
.ASCII
Place a string in memory using the ASCII character code
.TEXT
The following lines are instructions
Register Window
Displays value of machine registers when program is run Check after stopping at a breakpoint to aid debug
Data Window
Displays values of data in memory
Console Window
Used for Program Input and Output
Session Window
Displays Assembly Errors
MIPS Examples
# f=(g+h)-(i+j); # compiler puts f,g,h,i in # $16,$17,$18,$19,$20 add $8,$17,$18 # $8 =g+h add $9,$19,$20 #9=i+j sub $16,$8,$9 # $16=(g+h)-(i+j)
MIPS Examples
# g=h+A[i] # compiler puts g,h,i in $17,$18,$19 LW $8,Astart($19) # $8 = A[i] ADD $17,$18,$8 # $17 = h+A[i]
MIPS Examples
# A[i] = h + A[i]; # compiler puts g,h in $17,$18 # compiler puts i times 4 in $19 LW $8,Astart($19) # $8 = A[i] ADD $8,$18,$8 # $8 = h+A[i] SW $8,Astart($19) # A[i]=h+A[i]
MIPS Examples
#if (i==j) f=g+h;
MIPS Examples
#if (i==j) f=g+h; else f=g-h;
MIPS Examples
#for loop
$5,$0,10
$5,$5,-1 $5,$0,Loop