Download Computer Arithmetic

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
Computer Arithmetic:
Unsigned Notation
By Sherwin Chiu
Unsigned Notation

Introduction
 Definition of Unsigned Notation
 Addition
 Subtraction
 Multiplication
 Division
Introduction
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
Definition of Unsigned
Notation
Unsigned Notation: The notation does not
have a separate bit to represent the sign of
the number.
Unsigned Notation
There are two types of unsigned notation:
1.
2.
Non-negative notation
2’s complement notation
Non-negative versus
2’s complement
Binary Representation
Non-negative
2’s Complement
0000
0
0
0001
1
1
…
…
…
0111
7
7 (2 - 1)
1000
8
-8 (2 n-1 )
1001
9
-7
…
…
…
1111
15 (2ª - 1)
-1
n-1
Addition

Can be easily done when values fit the
limitations for non-negative or 2’s
complement

A little more complicated when it does not.
Straightforward 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.
Implementation of
ADD: XX+Y
Overflow

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 2’s complement, an overflow flag is
notified by both the carry in and carry out
bit.
Subtraction

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.
Implementation of
SUB: X X – Y
Multiplication

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.
People to Shift-Add
Multiplication
Binary Multiplication

Using binary notation makes multiplication
even easier by having only two possible
values, 0 (X · 0 = 0) or 1 (1 X · 1 = 1)
Shift-Add Multiplication
in RTL Form
X,U,V – n bit register
C – 1 bit register for carry
Start – initiates
U – high order half
V – low order half
Finish – terminates
1: U0, i n
Vo 2: CU U + X
2: i i – 1
3: shr(CUV)
Z’3: GOTO 2
Z 3: FINISH1
1: U0, i n
3: shr(CUV)
Conditions
Vo 2: CUU + X
Z’3: GOTO 2
Micro-operations
START
2: i i – 1
Z 3: FINISH1
i
C
U
V
x
x
xxxx
1011
1
U0, i  4
4
Vo 2,2
CUU+X, ii–1
3
3, Z’3
shr(CUV), GOTO 2
Vo 2,2
CUU+X, ii – 1
3, Z’3
shr(CUV), GOTO 2
2
ii – 1
3, Z’3
shr(CUV), GOTO 2
Vo 2,2
CUU+X, ii – 1
3, Z 3
shr(CUV), FINISH1
2
FINISH
0
0000
0
0
1101
0
0
0110
1
0011
0
1001
1101
0
1110
1
0
Z
0
0
0100
1
0001
0
1000
1111
1
1111
1
Implementation of Shift-Add
Multiplication Algorithm
Division

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.
Shift-Sub Division in RTL Form
X,Y,U,V – n bit register
C – 1 bit register for carry
Start – initiates
U – high order half
V – low order half
Finish – terminates
1 1: CUU+X’+1
1 2: U U+X
C1 2 : FINISH 1,OVERFLOW 1
2 : Y 0,OVERLOW 0,i n
3 : shl(CUV),shl(Y),i i-1
C4 1 : U U+X’+1
C’41 : CU U+X’+1
C4 2 : Y01
C’42 : U U+X
Z 4 2:FINISH 1
Z’4 2 :GOTO 3
X,Y,U,V – n bit register
C – 1 bit register for carry
Start – initiates
Conditions
Micro-operations
START
U – high order half
V – low order half
Finish – terminates
i
C
U
V
Y
x
x
1001
0011
xxxx
0
1100
11
CUU+X’+1
12
U U+X
2
Y 0,OVERFLOW 0,i 4
4
3
shl(CUV),shl(Y),i i-1
3
C41
U U+X’+1
C42,Z’42
Y0 1,GOTO 3
3
shl(CUV),shl(Y),i i-1
C’41
CU U+X’+1
C’42,Z’42
U U+X,GOTO 3
3
shl(CUV),shl(Y),i i-1
C41
U U+X’+1
C42,Z’42
Y0 1,GOTO 3
3
shl(CUV),shl(Y),i i-1
C41
U U+X’+1
C42,Z42
Y0 1,FINISH1
Z
FINISH
0
1001
1
0010
0110
0000
0
0000
0
0101
0001
2
0
1010
0
1101
1100
0010
0
1000
0100
0
1010
1
1
0101
1000
0101
0
1
0001
0000
1010
1
0100
1011
1
Implementation of shift-sub
division algorithm
Conclusion

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 binarycoded decimal.
 Any Questions?
Related documents