240 likes | 391 Views
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:
E N D
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: • Non-negative notation • 2’s complement notation
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.
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.
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.
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 U – high order half C – 1 bit register for carry V – low order half Start – initiates Finish – terminates 1: U0, i n Vo 2: CU U + X 2: i i – 1 3: shr(CUV) Z’3: GOTO 2 Z 3: FINISH1
1: U0, i n Vo 2: CUU + X 2: i i – 13: shr(CUV) Z’3: GOTO 2 Z 3: FINISH1
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 U – high order half C – 1 bit register for carry V – low order half Start – initiates Finish – terminates 1 : CUU+X’+1 1 : U U+X C1 : FINISH 1,OVERFLOW 1 2 : Y 0,OVERLOW 0,i n 3 : shl(CUV),shl(Y),i i-1 C4 : U U+X’+1 C’4 : CU U+X’+1 C4 : Y 1 C’4 : U U+X Z 4 :FINISH 1 Z’4 :GOTO 3 1 2 2 1 1 0 2 2 2 2
X,Y,U,V – n bit register U – high order halfC – 1 bit register for carry V – low order halfStart – initiates Finish – terminates i
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 binary-coded decimal. • Any Questions?