Title: Computer Arithmetic:
1Computer Arithmetic
- Unsigned Notation
- By Sherwin Chiu
2Unsigned Notation
- Introduction
- Definition of Unsigned Notation
- Addition
- Subtraction
- Multiplication
- Division
3Introduction
- Most frequently preformed operation is copying
data from one place to another - From one register to another
- Between a register and a memory location
- Value is not modified as it is copied
4Definition of Unsigned Notation
- Unsigned Notation The notation does not have a
separate bit to represent the sign of the number.
5Unsigned Notation
- There are two types of unsigned notation
- Non-negative notation
- 2s complement notation
6Non-negative versus 2s complement
Binary Representation Non-negative 2s Complement
0000 0 0
0001 1 1
0111 7 7 (2 - 1)
1000 8 -8 (2 )
1001 9 -7
1111 15 (2ª - 1) -1
n-1
n-1
7Addition
- Can be easily done when values fit the
limitations for non-negative or 2s complement - A little more complicated when it does not.
8Straightforward Addition
- Adding numbers that fit the limitations can
perform a straightforward addition of binary
numbers. - When adding two numbers of different signs (/-),
a valid result will always occur.
9Implementation of ADD X?XY
10Overflow
- When two numbers being added exceed the number of
bits available in the register, an overflow
occurs. - In non-negative, an overflow flag is notified by
the carry out bit. - In 2s complement, an overflow flag is notified
by both the carry in and carry out bit.
11Subtraction
- Essentially treated the same as addition, but
negating one of the values. X (-Y) - Overflow is still caused by exceeding the number
of bits available in the register.
12Implementation ofSUB X? X Y
13Multiplication
- We could multiply by adding n copies of the
number together, but it would be inefficient. - It is also not how people would do
multiplication.
14People to Shift-Add Multiplication
15Binary Multiplication
- Using binary notation makes multiplication even
easier by having only two possible values, 0 (X
0 0) or 1 (1 X 1 1)
16Shift-Add Multiplication in RTL Form
- X,U,V n bit register U
high order half - C 1 bit register for carry V
low order half - Start initiates
Finish terminates - 1 U?0, i ?n
- Vo 2 CU ?U X
- 2 i ?i 1
- 3 shr(CUV)
- Z3 GOTO 2
- Z 3 FINISH?1
171 U?0, i ?n Vo 2 CU?U X 2 i ?i
13 shr(CUV) Z3 GOTO 2 Z
3 FINISH?1
Conditions Micro-operations i C U V Z FINISH
START x x xxxx 1011 0
1 U?0, i ? 4 4 0000 0
Vo 2,2 CU?UX, i?i1 3 0 1101 0
3, Z3 shr(CUV), GOTO 2 0 0110 1101
Vo 2,2 CU?UX, i?i 1 2 1 0011 0
3, Z3 shr(CUV), GOTO 2 0 1001 1110
2 i?i 1 1 0
3, Z3 shr(CUV), GOTO 2 0 0100 1111
Vo 2,2 CU?UX, i?i 1 0 1 0001 1
3, Z 3 shr(CUV), FINISH?1 0 1000 1111 1
18Implementation of Shift-Add Multiplication
Algorithm
19Division
- Can be done with the same idea of repeated
additions like multiplication, but instead for
division, it is repeated subtractions. - Shifting is also applicable in the same way as
multiplication, just shifting left and
subtracting instead.
20Shift-Sub Division in RTL Form
- X,Y,U,V n bit register
U high order half - C 1 bit register for carry
V low order half - Start initiates
Finish terminates -
- 1 CU?UX1
- 1 U ?UX
- C1 FINISH ?1,OVERFLOW ?1
- 2 Y ?0,OVERLOW ?0,i ?n
- 3 shl(CUV),shl(Y),i ?i-1
- C4 U ?UX1
- C4 CU ?UX1
- C4 Y ?1
- C4 U ?UX
- Z 4 FINISH ?1
- Z4 GOTO 3
1
2
2
1
1
0
2
2
2
2
21X,Y,U,V n bit register
U high order halfC 1 bit register for
carry V low order
halfStart initiates
Finish terminates
Conditions Micro-operations C U V Y Z FINISH
START x x 1001 0011 xxxx 0
1 1 CU?UX1 0 1100
1 2 U ?UX 1001
2 Y ?0,OVERFLOW ?0,i ?4 4 0000 0
3 shl(CUV),shl(Y),i ?i-1 3 1 0010 0110 0000 0
C41 U ?UX1 0101
C42,Z42 Y0 ?1,GOTO 3 0001
3 shl(CUV),shl(Y),i ?i-1 2 0 1010 1100 0010 0
C41 CU ?UX1 0 1101
C42,Z42 U ?UX,GOTO 3 1010
3 shl(CUV),shl(Y),i ?i-1 1 1 0101 1000 0100 0
C41 U ?UX1 1000
C42,Z42 Y0 ?1,GOTO 3 0101
3 shl(CUV),shl(Y),i ?i-1 0 1 0001 0000 1010 1
C41 U ?UX1 0100
C42,Z42 Y0 ?1,FINISH?1 1011 1
i
22Implementation of shift-sub division algorithm
23Conclusion
- Basic arithmetic functions are a lot more
complicated than what it seems. - These implementations are only for unsigned
notation. - There still exist signed notation and
binary-coded decimal. - Any Questions?