Professional Documents
Culture Documents
Review: MIPS Organization: Processor Memory
Review: MIPS Organization: Processor Memory
Processor
src1 addr src2 addr dst addr write data 5 32 32 bits branch offset 32 PC 4 32 Add 32 Add 32 32 ALU 32 32 32 src1 32 data
Memory
11100
5 5
src2 32 data
read/write addr
32
230 words
read data
32
write data
32 32 4 0 5 1 6 2 7 3
Decode
Possible Representations
Sign Magnitude: One's Complement Two's Complement
maxint
1111 1111 1111 1111 1111 1111 1111 1110two = 2ten 1111 1111 1111 1111 1111 1111 1111 1111two = 1ten
MSB LSB
minint
Converting <32-bit values into 32-bit values copy the most significant bit (the sign bit) into the empty bits 0010 -> 0000 0010 1010 -> 1111 1010 sign extend versus zero extend (lb vs. lbu)
A B
0 1 1 1 1
S = A B carry_in
How can we use it to build a 32-bit adder? How can we modify it easily to build an adder/subtractor?
CSE 338 Computer Organization CHAPTER 3
add/sub A0 B0 A1 B1 A2
S1
S2
add a 1 in the least significant bit A 0111 B - 0110 0001 0111 + 1001 1 1 0001
B2
c32=carry_out
0110 - 0101
Detecting Overflow
No overflow when adding a positive and a negative number No overflow when signs are the same for subtraction Overflow occurs when the value affects the sign: overflow when adding two positives yields a negative or, adding two negatives gives a positive or, subtract a negative from a positive and get a negative or, subtract a positive from a negative and get a positive
Effects of Overflow
An exception (interrupt) occurs Control jumps to predefined address for exception Interrupted address is saved for possible resumption Details based on software system / language Don't always want to detect overflow new MIPS instructions: addu, addiu, subu
note: addiu still sign-extends! note: sltu, sltiu for unsigned comparisons
10
Multiply
Binary multiplication is just a bunch of right shifts and adds
n
multiplicand multiplier partial product array can be formed in parallel and added in parallel for faster multiplication
2n
Negative numbers: convert and multiply ** there are better techniques
CSE 338 Computer Organization CHAPTER 3
11
Multiplication: Implementation
Start
Multiplier0 = 1
1. Test Multiplier0
Multiplier0 = 0
64-bit ALU
Control test
3. Shift the Multiplier register right 1 bit
Datapath Control
CSE 338 Computer Organization CHAPTER 3
Yes: 32 repetitions Done
12
Final Version
Start
Multiplicand 32 bits
Product0 = 1 1. Test Product0 Product0 = 0
32-bit ALU
1a. Add multiplicand to the left half of the product and place the result in the left half of the Product register
Product 64 bits
Control test
32nd repetition?
Yes: 32 repetitions
Done
13
Low-order word of the product is left in processor register lo and the high-order word is left in register hi Instructions mfhi rd and mflo rd are provided to move the product to (user accessible) registers in the register file
Multiplies are done by fast, dedicated hardware and are much more complex (and slower) than adders
14
15
Start
2. Subtract the Divisor register from the left half of the Remainder register and place the result in the left half of the Remainder register
Remainder > 0
Test Remainder
Remainder < 0
3a. Shift the Remainder register to the left, setting the new rightmost bit to 1
3b. Restore the original value by adding the Divisor register to the left half of the Remainder register and place the sum in the left half of the Remainder register. Also shift the Remainder register to the left, setting the new rightmost bit to 0
32nd repetition?
Yes: 32 repetitions
16
Instructions mfhi rd and mflo rd are provided to move the quotient and reminder to (user accessible) registers in the register file
As with multiply, divide ignores overflow so software must determine if the quotient is too large. Software must also check the divisor to avoid division by 0.
17
18
19
1. Compare the exponents of the two numbers. Shift the smaller number to the right until its exponent would match the larger exponent
3. Normalize the sum, either shifting right and incrementing the exponent or shifting left and decrementing the exponent
Overflow or underflow? No
Yes
Exception
No Still normalized?
Yes
20
Small ALU
Exponent difference 0 1 0 1 0 1
Control
Shift right
Big ALU
Increment or decrement
Rounding hardware
Sign
Exponent
Fraction
21
And supports IEEE 754 single add.s $f2,$f4,$f6 #$f2 = $f4 + $f6 and double precision operations #$f2||$f3 = $f4||$f5 + $f6||$f7 similarly for sub.s, sub.d, mul.s, mul.d, div.s, div.d add.d $f2,$f4,$f6
22
23
24
25