970 likes | 1.66k Views
Instruction Set Architecture An overview of MIPS R3000 assembly language. Overview. Review of the concept of an Instruction SetArchitecture (ISA) Understand the format of MIPS assembly source files Be able to identify the registers of the R3000 and their purpose
E N D
Instruction Set Architecture An overview of MIPS R3000 assembly language SYCS-401 Operating Systems
Overview • Review of the concept of an Instruction SetArchitecture (ISA) • Understand the format of MIPS assembly source files • Be able to identify the registers of the R3000 and their purpose • Be able to understand the effects of a subset of instructions of the MIPS R3000 Instruction Set Architecture (ISA) SYCS-401 Operating Systems
Opcodes and Operands add $a0, $t1, $t0 Operands (“arguments”) Opcode (Instruction) SYCS-401 Operating Systems
Simple Assembler Program .globl main .text main: # Program starts here. li $t0, 5 # Load the integer value 5 # into register t0 li $t1, 19 # Load 19 into register t1 add $t2, $t1, $t0 # Add registers t0 and t1 # to produce t2 li $v0, 1 # Setup a print integer call # to print the result move $a0, $t2 syscall li $v0, 10 # Setup an exit call syscall # Do the exit thing Add the integers 5 and 19, and print the result. 8 SYCS-401 Operating Systems
Instruction Set Architecture (ISA) • Think of the ISA as the hardware/software interface • In this lecture we look at some aspects of MIPS ISA, • including: • Some opcodes • Required operands • there are no implicit operands in MIPS • Means of accessing RAM • Number of registers • Instruction format • etc., etc. SYCS-401 Operating Systems
MIPS: ISA generations (‘I’ to ‘IV’) • MIPS I (8 MHz, 32b architecture) • R2000 (first commercial MIPS processor) • MIPS II (40 MHz, 32b architecture) • R3000 • MIPS III (to 250 MHz pipeline, 64b architecture) • R4x00 • MIPS IV • R8000 • R10000 • R5000 SYCS-401 Operating Systems
MIPS Registers SYCS-401 Operating Systems
General-Purpose Registers SYCS-401 Operating Systems
General-Purpose Registers SYCS-401 Operating Systems
General-Purpose Registers SYCS-401 Operating Systems
General-Purpose Registers SYCS-401 Operating Systems
General-Purpose Registers SYCS-401 Operating Systems
General-Purpose Registers SYCS-401 Operating Systems
General-Purpose Registers SYCS-401 Operating Systems
General-Purpose Registers SYCS-401 Operating Systems
MIPS opcode formats SYCS-401 Operating Systems
MIPS Instruction Categories • Arithmetic instructions • add, subtract, multiply, divide comparison • Logical instructions • Branch and jump instructions • conditional (branch) • unconditional (jump) • Data transfer (load & store) instructions SYCS-401 Operating Systems
Arithmetic Instructions • add • subtract • multiply • divide • compare • shift / rotate • not covered here SYCS-401 Operating Systems
Arithmetic Instructions: Add Registers ADD destinationReg, sourceReg, targetReg Destination ¬Source + Target SYCS-401 Operating Systems
Arithmetic Instructions: Add Unsigned ADDU destinationReg, sourceReg, targetReg Destination ¬Source + Target SYCS-401 Operating Systems
Arithmetic Instructions: Add Immediate ADDI destinationReg, sourceReg, targetReg Destination ¬Source + Target SYCS-401 Operating Systems
MIPS Opcode Map SYCS-401 Operating Systems
MIPS Opcode Map SYCS-401 Operating Systems
MIPS System Calls (syscall) SYCS-401 Operating Systems
Arithmetic Instructions: Divide Registers DIV sourceReg, targetReg $lo (quotient), $hi (remainder) ¬Source / Target SYCS-401 Operating Systems
Arithmetic Instructions: Multiply Registers MUL sourceReg, targetReg $lo (low word), $hi (high word) ¬Source x Target SYCS-401 Operating Systems
Arithmetic Instructions: Set if Less Than SLT destinationReg, sourceReg, targetReg Destination ¬(Source < Target) ? 1 : 0 SYCS-401 Operating Systems
Arithmetic Instructions: SLT Immediate SLTI destinationReg, sourceReg, immediate Destination ¬(Source < immediate) ? 1 : 0 SYCS-401 Operating Systems
Some other arithmetic instructions SYCS-401 Operating Systems
Logical Instructions • Logical AND • logical OR • XOR • NOT SYCS-401 Operating Systems
Arithmetic Instructions: Logical AND AND destinationReg, sourceReg, targetReg Destination ¬Source AND Target SYCS-401 Operating Systems
Arithmetic Instructions: Logical OR OR destinationReg, sourceReg, targetReg Destination ¬Source OR Target SYCS-401 Operating Systems
Some other Logical instructions SYCS-401 Operating Systems
Branch and Jump Instructions • These alter the (otherwise) linear flow of control. • There are two main types of “go to” instruction • unconditional ( always go to … ) • > jump • conditional ( if … then go to … ) • > branch (indicating an alternative flow) SYCS-401 Operating Systems
Branch and Jump Instructions SYCS-401 Operating Systems
Jump Instructions: Jump J label Jump to instruction at label SYCS-401 Operating Systems
Jump Instructions: Jump & Link JAL label Place the address of the next instruction (PC + 4) in $ra. Jump to the instruction at ‘label’ SYCS-401 Operating Systems
Jump Instructions: Jump & Link SYCS-401 Operating Systems
Branch Instructions: Branch on Equal BEQ sourceRegister, targetRegister, label If (sourceRegister == targetRegister) go to instruction at ‘label’ SYCS-401 Operating Systems
Branch Instructions: Branch if Equal to Zero BEQZ sourceRegister, label If (sourceRegister == 0) go to instruction at ‘label’ SYCS-401 Operating Systems
Some other Jump/Branch instructions SYCS-401 Operating Systems
Data transfer instructions • MIPS is a load-and-store architecture • The only instructions that access RAM are those\ which load to (or store from) registers • Note that all other instructions operate on registers • To change a value in memory, you must therefore: • load it to a register • alter it • store it back in memory SYCS-401 Operating Systems
Data Transfer Instructions: Load Address LA destinationRegister, address destinationRegister ¬calculated address SYCS-401 Operating Systems
Data Transfer Instructions: Load Immediate LI destinationRegister, immediate destinationRegister ¬immediate value SYCS-401 Operating Systems
Data Transfer Instructions: Move from HI MFHI destinationRegister destinationRegister ¬HI register SYCS-401 Operating Systems
Data Transfer Instructions: Load Byte LB targetRegister, label Load targetRegister with the byte value at address “label” SYCS-401 Operating Systems
Data Transfer Instructions: Store Byte SB targetRegister, label Store low byte value in targetRegister at address “label” SYCS-401 Operating Systems
Data Transfer Instructions: Load Word LW targetRegister, label Load targetRegister with the word value at address “label” SYCS-401 Operating Systems
Data Transfer Instructions: Move MOVE destinationRegister, sourceRegister destinationRegister ¬sourceRegister SYCS-401 Operating Systems