Presentation is loading. Please wait.

Presentation is loading. Please wait.

Number Systems and Arithmetic or Computers go to elementary school Reading – 4.1-4.3 Peer Instruction Lecture Materials for Computer Architecture by Dr.

Similar presentations


Presentation on theme: "Number Systems and Arithmetic or Computers go to elementary school Reading – 4.1-4.3 Peer Instruction Lecture Materials for Computer Architecture by Dr."— Presentation transcript:

1 Number Systems and Arithmetic or Computers go to elementary school Reading – 4.1-4.3 Peer Instruction Lecture Materials for Computer Architecture by Dr. Leo Porter is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License. Dr. Leo Porter Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License

2 What do all those bits mean now? bits (011011011100010....01) instruction R-formatI-format... data numbertext chars.............. integerfloating point signedunsigned single precisiondouble precision...

3 Questions About Numbers How do you represent –negative numbers? –fractions? –really large numbers? –really small numbers? How do you –do arithmetic? –identify errors (e.g. overflow)? What is an ALU and what does it look like? –ALU=arithmetic logic unit

4 Two’s Complement Representation 2’s complement representation of negative numbers –Take the bitwise inverse and add 1 Biggest 4-bit Binary Number: 7 Smallest 4-bit Binary Number: -8 Decimal -8 -7 -6 -5 -4 -3 -2 0 1 2 3 4 5 6 7 Two’s Complement Binary 1000 1001 1010 1011 1100 1101 1110 1111 0000 0001 0010 0011 0100 0101 0110 0111 Point out negatives, sign bit, how to convert a 2’s complement number

5 Some Things We Want To Know About Our Number System negation sign extension –+3 => 0011, 00000011, 0000000000000011 – -3 => 1101, 11111101, 1111111111111101

6 Introduction to Binary Numbers Consider a 4-bit binary number Examples of binary arithmetic: 3 + 2 = 53 + 3 = 6 Binary Decimal 00000 10001 20010 30011 Decimal 40100 50101 60110 70111 0011 0010+ 1 0011 0011+ 11 Walk through the add

7 Can we use that same procedure for adding 2’s complement negative #s as unsigned #s? 0011 0010+ 1 1011 1110+ 1 1111 0010+ 1 1 1 3+2 = 5 -5+-2 = -7 1 -1+2 = 1 Selection“Best” Statement AYes – the same procedure applies BYes – the same “procedure” applies but it changes overflow detection CNo – we need a new procedure DNo – we need a new procedure and new hardware to implement it ENone of the above

8 Overflow Detection 0111 0011+ 1010 1 1100 1011+ 0111 110 7 3 1 -6 - 4 - 5 7 0 0010 0011+ 0101 1 1100 1110+ 1010 100 2 3 0 5 - 4 - 2 - 6 100 10 So how do we detect overflow for signed arithmetic?

9 2’s complement? We would like a number system that provides –obvious representation of 0,1,2... – –single value of 0 –equal coverage of positive and negative numbers –easy detection of sign –easy negation uses adder for all addition Two’s complement gives us this.

10 Arithmetic -- The heart of instruction execution 32 operation result a b ALU Instruction Fetch Instruction Decode Operand Fetch Execute Result Store Next Instruction

11 Designing an Arithmetic Logic Unit ALU Control Lines (ALUop)Function –000 And –001 Or –010 Add –110 Subtract –111 Set-on-less-than ALU N N N A B Result Overflow Zero 3 ALUop CarryOut

12 A One Bit ALU This 1-bit ALU will perform AND, OR, and ADD 1100 1110+ 1010 1 - 4 - 2 - 6 100

13 A 32-bit ALU 1-bit ALU 32-bit ALU

14 Subtract – We’d like to implement a means of doing A-B (subtract) but with only minor changes to our hardware. How? 1. Provide an option to use bitwise NOT A 2. Provide an option to use bitwise NOT B 4. Provide an option to use 0 instead of the first CarryIn 5. Provide an option to use 1 instead of the first CarryIn 3. Provide an option to use bitwise A XOR B Explain “Provide an Option”. SelectionChoices A1 alone BBoth 1 and 2 CBoth 3 and 4 DBoth 2 and 5 ENone of the above

15 Full ALU sign bit (adder output from bit 31) what signals accomplish ADD? Binvert CIn Oper A1 0 2 B 0 1 2 C 1 1 2 D 0 0 2 E NONE OF THE ABOVE ISOMORPHIC

16 Full ALU sign bit (adder output from bit 31) what signals accomplish OR? Binvert CIn Oper A1 0 0 B 0 1 1 C 1 1 0 D 1 0 1 E NONE OF THE ABOVE ISOMORPHIC Careful – B is correct but E isn’t that far off

17 Full ALU sign bit (adder output from bit 31) what signals accomplish SUB? Binvert CIn Oper A1 0 2 B 0 1 2 C 1 1 2 D 0 0 2 E NONE OF THE ABOVE Little more intense – can you get this?

18 Full ALU sign bit (adder output from bit 31) Recall: slt $t0, $t1, $t2 Means: if($t1<$t2) $t0 = 1 else $t0 = 0 Which signals accomplish SLT (assume A is in $t1, B in $t2) (Note that the output “Set” is always passed – what operation ensures it is correct.)? Binvert CIn Oper A1 0 2 B 0 1 2 C 1 1 3 D 0 0 3 E NONE OF THE ABOVE Even harder…. Point out set bit is bit 31 from adder

19 Full ALU sign bit (adder output from bit 31) what signals accomplish: Binvert CIn Oper add? sub? and? or? beq? slt? For practice

20 The Disadvantage of Ripple Carry The adder we just built is called a “Ripple Carry Adder” –The carry bit may have to propagate from LSB to MSB –Worst case delay for an N-bit RC adder: 2N-gate delay A0 B0 1-bit ALU Result0 CarryOut0 A1 B1 1-bit ALU Result1 CarryIn1 CarryOut1 A2 B2 1-bit ALU Result2 CarryIn2 A3 B3 1-bit ALU Result3 CarryIn3 CarryOut3 CarryOut2 CarryIn0 CarryIn CarryOut A B The point -> ripple carry adders are slow. Faster addition schemes are possible that accelerate the movement of the carry from one end to the other. Now we’re diving more into CSE140 stuff, let’s step back

21 MULTIPLY HARDWARE 64-bit Multiplicand reg, 64-bit ALU, 64-bit Product reg, 32-bit multiplier reg Here’s the hardware to do multiply/divide, they USE an adder multiple times.

22 DIVIDE HARDWARE 64-bit Divisor reg, 64-bit ALU, 64-bit Remainder reg, 32-bit Quotient reg Here’s the hardware to do multiply/divide, they USE an adder multiple times.

23 You already know a way to write faster code. Let’s say you have code which does: A = B*8. What might you replace that code with to speed up execution (which answer is best) by leveraging faster hardware? SelectionChoices ADo A = B+B+B+B+B+B+B+B BDo A = B sll 3 CDo A = B sra 3 DDo A = B srl 3 ENone of the above Point out a compiler might do this for you.

24 Floating-Point Numbers Representation of floating point numbers in IEEE 754 standard: single precision 1823 sign exponent: excess 127 binary integer mantissa: sign + magnitude, normalized binary significand w/ hidden integer bit: 1.M (actual exponent is e = E - 127) SE M Need to be able to convert both directions. SelectionChoices A- 1.010 * 2^130 B - 10 C+10 D1.010 * 2^130 ENone of the above Convert the following: 1 1000 0010 0100 0000 0000 0000 0000 000

25 FP Addition Hardware Need to normalize – the key here is this is more complex than Integer Add but not as bad as, say, integer multiply.

26 Modern Concerns Hardware designers have done an excellent job optimizing multiply/FP hardware, but additions are still faster, than, say multiply. Divides are even slower and have other problems. More complex topics in later lectures will show how multiply/FP/divide may not be on the “critical path” and hence may not hurt performance as much as expected. More recent years have taught us that even “slow” multiply is not nearly as important as cache/memory issues we’ll discuss in later lessons.


Download ppt "Number Systems and Arithmetic or Computers go to elementary school Reading – 4.1-4.3 Peer Instruction Lecture Materials for Computer Architecture by Dr."

Similar presentations


Ads by Google