You are on page 1of 23

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 2s complement notation

Non-negative versus 2s complement


Binary Representation 0000 Non-negative 0 2s Complement 0

0001
0111 1000 1001 1111

1
7 8 9 15 (2 - 1)

1
7 (2 - 1) -8 (2 n-1 ) -7 -1
n-1

Addition

Can be easily done when values fit the limitations for non-negative or 2s 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: XX+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 2s 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: U0, i n Vo 2: CU U + X 2: i i 1 3: shr(CUV) Z3: GOTO 2 Z 3: FINISH1

1: U0, i n 3: shr(CUV) Conditions START 1 Vo 2,2 3, Z3 Vo 2,2 3, Z3 2 3, Z3 Vo 2,2 3, Z 3

Vo 2: CUU + X Z3: GOTO 2 Micro-operations U0, i 4 CUU+X, ii1 shr(CUV), GOTO 2 CUU+X, ii 1 shr(CUV), GOTO 2 ii 1 shr(CUV), GOTO 2 CUU+X, ii 1 shr(CUV), FINISH1

2: i i 1 Z 3: FINISH1 i x 4 3 0 0 2 1 0 1 0 0 1 0 0100 0001 1000 1111 1111 1 1 C x U xxxx 0000 1101 0110 0011 1001 1110 0 1101 0 V 1011 0 0 Z FINISH 0

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: CUU+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 C41 : CU U+X+1 C4 2 : Y 1 0 C42 : U U+X Z 4 2:FINISH 1 Z4 2 :GOTO 3

X,Y,U,V n bit register C 1 bit register for carry Start initiates


Conditions START 11 12 2 3 C41 CUU+X+1 U U+X Y 0,OVERFLOW 0,i 4 shl(CUV),shl(Y),i i-1 U U+X+1 4 3 1 Micro-operations i x C x 0

U high order half V low order half Finish terminates


U 1001 1100 1001 0000 0010 0101 0110 0000 0 0 V 0011 Y xxxx Z FINISH 0

C42,Z42
3

Y0 1,GOTO 3
shl(CUV),shl(Y),i i-1 2 0 1010 1100

0001
0010 0

C41
C42,Z42 3 C41

CU U+X+1
U U+X,GOTO 3 shl(CUV),shl(Y),i i-1 U U+X+1 1

1101
1010

0101 1000

1000

0100

C42,Z42
3 C41 C42,Z42

Y0 1,GOTO 3
shl(CUV),shl(Y),i i-1 U U+X+1 Y0 1,FINISH1 0 1 0001 0100 0000

0101
1010 1

1011

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?

You might also like