SLIDE 3 10.9
IMPORTANT R-TYPE INSTRUCTIONS
Performing Arithmetic, Logic, and Shift Operations
10.10
R-Type Arithmetic/Logic Instructions
C operator Assembly Notes + ADD $d, $s, $t d=destination, s = src1, t = src2
Order: $s – $t. SUBU for unsigned * MUL $d, $s, $t If multiply won’t overflow 32-bit result & AND $d, $s, $t | OR $d, $s, $t ^ XO$ $d, $s, $t ~( | ) NOR $d, $s, $t Can be used for bitwise-NOT (~) << SLL $d, $s, shamt SLLV $d, $s, $t Shifts $s left by shamt (shift amount)
>> (signed) SRA $d, $s, shamt SRAV $d, $s, $t Shifts $s right by shamt or $t bits replicating sign bit to maintain sign >> (unsigned) SRL $d, $s, shamt SRLV $d, $s, $t Shifts $s left by shamt or $t bits shifting in 0’s <, >, <=, >= SLT $d, $s, $t SLTU $d, $s, $t
- Comparison. Order: $s – $t. Sets
$d=1 if $s < $t, $d=0 otherwise * MULT $s, $t MULTU $s, $t Result in HI/LO. Use mfhi and mflo instruction to move results / DIV $s, $t DIVU $s, $t $[s] / $[t]. Remainder in HI, quotient in LO
10.11
R-Type Instructions
C Code MIPS Assembly
F = X + Y – Z; G = F | Z;
LOAD* $4, X # Get X from mem. LOAD _____ # Get Y from mem. LOAD _____ # Get Z from mem. ADD _______ # Tmp = X+Y SUB _______ # Tmp = Tmp - Z STORE _______ # Store to F in mem OR _______ # Tmp2 = F | Z STORE $8, G # Store to G in mem * LOAD/STORE are not actual instructions. We will learn the actual syntax soon.
- To perform arithmetic or logic operations in many processors (MIPS
included) a copy of the operand MUST be loaded into a register first
- Consider the following operations
– F = X + Y – Z – G = F | Z
- Complete the assembly code
to perform these operations
– Remember to load/store your
- perands to/from registers
MIPS Processor
Addr (32-bits) Data (32-bits) Control
Memory
Load 00400000
ALU
ADD, SUB, AND, OR
in1 in2
PC $0-$31 (32-bits each) (32-bits ALU) Load … Store X (e.g. 12) Y (e.g. 7) Z (e.g. 3) F G $4 $5 $6 $7 $8 00400004 10010000 10010004 10.12
R-Type Instructions
– rs, rt, rd are 5-bit fields for register numbers – shamt = shift amount and is used for shift instructions indicating # of places to shift bits – opcode and func identify actual operation (e.g. ADD, SUB)
– ADD $5, $24, $17
rs (src1) 6-bits 5-bits rt (src2) 5-bits rd (dest) 5-bits shamt 5-bits function 6-bits 000000
rs rt rd 00000 shamt 100000 func
$24 $17 $5 unused ADD