287 pág.

# 278500-Apresentações

DisciplinaArquitetura e Organização de Computadores 1275 materiais4.375 seguidores
Pré-visualização17 páginas
```gets more complicated:
numbers are finite (overflow)
fractions and real numbers
negative numbers
\u2022 How do we represent negative numbers?
i.e., which bit patterns will represent which numbers?
Numbers
61\uf6d92004 Morgan Kaufmann Publishers
\u2022 Sign Magnitude: One's Complement Two's Complement
000 = +0 000 = +0 000 = +0
001 = +1 001 = +1 001 = +1
010 = +2 010 = +2 010 = +2
011 = +3 011 = +3 011 = +3
100 = -0 100 = -3 100 = -4
101 = -1 101 = -2 101 = -3
110 = -2 110 = -1 110 = -2
111 = -3 111 = -0 111 = -1
\u2022 Issues: balance, number of zeros, ease of operations
\u2022 Which one is best? Why?
Possible Representations
62\uf6d92004 Morgan Kaufmann Publishers
\u2022 32 bit signed numbers:
0000 0000 0000 0000 0000 0000 0000 0000two = 0ten
0000 0000 0000 0000 0000 0000 0000 0001two = + 1ten
0000 0000 0000 0000 0000 0000 0000 0010two = + 2ten
...
0111 1111 1111 1111 1111 1111 1111 1110two = + 2,147,483,646ten
0111 1111 1111 1111 1111 1111 1111 1111two = + 2,147,483,647ten
1000 0000 0000 0000 0000 0000 0000 0000two = \u2013 2,147,483,648ten
1000 0000 0000 0000 0000 0000 0000 0001two = \u2013 2,147,483,647ten
1000 0000 0000 0000 0000 0000 0000 0010two = \u2013 2,147,483,646ten
...
1111 1111 1111 1111 1111 1111 1111 1101two = \u2013 3ten
1111 1111 1111 1111 1111 1111 1111 1110two = \u2013 2ten
1111 1111 1111 1111 1111 1111 1111 1111two = \u2013 1ten
maxint
minint
MIPS
63\uf6d92004 Morgan Kaufmann Publishers
\u2022 Negating a two's complement number: invert all bits and add 1
\u2013 remember: \u201cnegate\u201d and \u201cinvert\u201d are quite different!
\u2022 Converting n bit numbers into numbers with more than n bits:
\u2013 MIPS 16 bit immediate gets converted to 32 bits for arithmetic
\u2013 copy the most significant bit (the sign bit) into the other bits
0010 -> 0000 0010
1010 -> 1111 1010
\u2013 &quot;sign extension&quot; (lbu vs. lb)
Two's Complement Operations
64\uf6d92004 Morgan Kaufmann Publishers
\u2022 Just like in grade school (carry/borrow 1s)
0111 0111 0110
+ 0110 - 0110 - 0101
\u2022 Two's complement operations easy
\u2013 subtraction using addition of negative numbers
0111
+ 1010
\u2022 Overflow (result too large for finite computer word):
\u2013 e.g., adding two n-bit numbers does not yield an n-bit number
0111
+ 0001 note that overflow term is somewhat misleading,
1000 it does not mean a carry \u201coverflowed\u201d
65\uf6d92004 Morgan Kaufmann Publishers
\u2022 No overflow when adding a positive and a negative number
\u2022 No overflow when signs are the same for subtraction
\u2022 Overflow occurs when the value affects the sign:
\u2013 overflow when adding two positives yields a negative
\u2013 or, adding two negatives gives a positive
\u2013 or, subtract a negative from a positive and get a negative
\u2013 or, subtract a positive from a negative and get a positive
\u2022 Consider the operations A + B, and A \u2013 B
\u2013 Can overflow occur if B is 0 ?
\u2013 Can overflow occur if A is 0 ?
Detecting Overflow
66\uf6d92004 Morgan Kaufmann Publishers
\u2022 An exception (interrupt) occurs
\u2013 Control jumps to predefined address for exception
\u2013 Interrupted address is saved for possible resumption
\u2022 Details based on software system / language
\u2013 example: flight control vs. homework assignment
\u2022 Don't always want to detect overflow
note: sltu, sltiu for unsigned comparisons
Effects of Overflow
67\uf6d92004 Morgan Kaufmann Publishers
\u2013 accomplished via shifting and addition
\u2022 More time and more area
\u2022 Let's look at 3 versions based on a gradeschool algorithm
0010 (multiplicand)
__x_1011 (multiplier)
\u2022 Negative numbers: convert and multiply
\u2013 there are better techniques, we won\u2019t look at them
Multiplication
68\uf6d92004 Morgan Kaufmann Publishers
Multiplication: Implementation
Datapath
Control
Multiplicand
Shift left
64 bits
64-bit ALU
Product
Write
64 bits
Control test
Multiplier
Shift right
32 bits
32nd repetition?
1a. Add multiplicand to product and
place the result in Product register
Multiplier0 = 01. Test
Multiplier0
Start
Multiplier0 = 1
2. Shift the Multiplicand register left 1 bit
3. Shift the Multiplier register right 1 bit
No: < 32 repetitions
Yes: 32 repetitions
Done
69\uf6d92004 Morgan Kaufmann Publishers
Final Version
Multiplicand
32 bits
32-bit ALU
Product
Write
64 bits
Control
test
Shift right
What goes here?
\u2022Multiplier starts in right half of product
32nd repetition?
Product0 = 01. Test
Product0
Start
Product0 = 1
3. Shift the Product register right 1 bit
No: < 32 repetitions
Yes: 32 repetitions
Done
70\uf6d92004 Morgan Kaufmann Publishers
Versão mais rápida
1 bit
32 bits
Mplier3 \u2022 Mcand
1 bit
32 bits
Mplier0 \u2022 McandMplier1 \u2022 Mcand
32 bits
Mplier2 \u2022 Mcand
1 bit
1 bit
32 bits
Mplier3 \u2022 Mcand
32 bits
Product63..32 Product 31 Product2 Product1 Product0
71\uf6d92004 Morgan Kaufmann Publishers
Divisão
Divisor
Shift right
64 bits
64-bit ALU
Remainder
Write
64 bits
Control
test
Quotient
Shift left
32 bits
72\uf6d92004 Morgan Kaufmann Publishers
Algoritmo
33rd repetition?
2a. Shift the Quotient register to the left,
setting the new rightmost bit to 1
Remainder < 0
Test Remainder
Start
Remainder \u2265 0
3. Shift the Divisor register right 1 bit
No: < 33 repetitions
Yes: 33 repetitions
Done
1. Subtract the Divisor register from the
Remainder register and place the
result in the Remainder register
2b. Restore the original value by adding
the Divisor register to the Remainder
register and place the sum in the
Remainder register. Also shift the
Quotient register to the left, setting the
new least significant bit to 0
73\uf6d92004 Morgan Kaufmann Publishers
Floating Point
\u2022 We need a way to represent
\u2013 numbers with fractions, e.g., 3.1416
\u2013 very small numbers, e.g., .000000001
\u2013 very large numbers, e.g., 3.15576 ×××× 109
\u2022 Representation:
\u2013 sign, exponent, significand: (\u20131)sign ×××× significand ×××× 2exponent
\u2013 more bits for significand gives more accuracy
\u2013 more bits for exponent increases range
\u2022 Overflow
\u2022 Underflow
74\uf6d92004 Morgan Kaufmann Publishers
Como representar?
\u2013 Números da forma 1,XXXXXXX
\u2013 Não é necessário armazenar o 1,
\u2022 Representação com 32 bits (precisão simples)
\u2022 Representação com 64 bits (precisão dupla)
0
7
0
6
0
5
0
4
0
3
0
2
0
1
MantissaExpoenteS
0
0
0
8
0
9
1
0
1
1
1
2
1
3
1
4
1
5
1
6
1
7
1
8
1
9
2
0
2
1
2
2
2
3
2
4
2
5
2
6
2
7
2
8
2
9
3
0
3
1
MantissaExpoenteS
0
7
0
6
0
5
0
4
0
3
0
2
0
1
0
0
0
8
0
9
1
0
1
1
1
2
1
3
1
4
1
5
1
6
1
7
1
8
1
9
2
0
2
1
2
2
2
3
2
4
2
5
2
6
2
7
2
8
2
9
3
0
3
1
Mantissa
0
7
0
6
0
5
0
4
0
3
0
2
0
1
0
0
0
8
0
9
1
0
1
1
1
2
1
3
1
4
1
5
1
6
1
7
1
8
1
9
2
0
2
1
2
2
2
3
2
4
2
5
2
6
2
7
2
8
2
9
3
0
3
1
75\uf6d92004 Morgan Kaufmann Publishers
IEEE 754 floating-point standard
\u2022 IEEE 754 floating point standard:
\u2013 single precision: 8 bit exponent, 23 bit significand
\u2013 double precision: 11 bit exponent, 52 bit significand
\u2022 Exponent is \u201cbiased\u201d to make sorting easier
\u2013 all 0s is smallest exponent all 1s is largest
\u2013 bias of 127 for single precision and 1023 for double precision
\u2013 summary: (\u20131)sign ×××× (1+(1+(1+(1+significand) ×××× 2exponent \u2013 bias
\u2022 Example:
\u2013 decimal: -.75 = - ( ½ + ¼ )```