Anda di halaman 1dari 15

Addition of integer and real

numbers
The basic rules for adding binary
integer numbers
1. The subtraction operation is changed by the addition
operation with a negative number.
2. Summands must have the same number of digits.
Insignificant zeros can be added to the left of an integer
part of a number.
3. Every summands are represent in modified Inverse or
Complement codes. Added insignificant zeros change
their significance with transformations according to the
general rule.
The basic rules for adding binary
integer numbers
4. Bit of sign take part in an additional operation
the same way the others bits.
5. For invert code if a carry bit is 1, should to
add this value to the low bit of sum.
6. When using a complement code a carry bit is
lost.
7. The result of a sign is generated automatically.
The basic rules for adding binary
integer numbers
8. The result of adding is represented in the code of
summands.
9. If the sign digits are different, it's overflow of a bit grid.
We should shift the information bits by one bit right. Then
we need to add one bit before sign bit and duplicated in
this bit the value of the leftmost sign bit.
10.For checking, the result of adding is converted into the
direct code.
Example 1. Part 1.
A = 710 B = 2510. Perform operations C = A - B in the
complement codes.
XOR AX,AX Reset AX AX: 00 00
XOR BX,BX Reset BX BX: 00 00
MOV AX, A Moving A=7 10 h AX: 00 07 AX:0000 0000 0000 0111
into register АХ 0 0 0 7
MOV BX, B Moving number BX: 00 19 BX: 0000 0000 0001 1001
B=2510 into 0 0 1 9
register BХ
NOT BX Inversion BX BX:FF E6 BX:0000 0000 0001 1001
BX:1111 1111 1110 0110
F F E 6
ADD BX,1 Additional BX: FF E7 BX: 1111 1111 1110 0110
BX,1 0000 0000 0000 0001
1111 1111 1110 0111
F F E 7
Example 1. Part 2.

ADD AX,BX Additional AX:FF EE AX: 0000 0000 0000 0111


AX,BX 1111 1111 1110 0111
1111 1111 1110 1110
F F E E
NOT AX Inversion AX AX: 00 11 AX: 1111 1111 1110 1110
0000 0000 0001 0001
0 0 1 1
ADD AX, 00 01 Additional AX: 00 02 AX: 0000 0000 0001 0001
AX,1 0000 0000 0000 0001
0000 0000 0001 0010
0 0 1 2
C10 = 18
The basic rules for adding real
numbers
1. The subtraction operation is changed by the
addition operation with a negative number
2. We should to level the order (characteristic)
of the summands. For it, we find C - the
difference of the orders of our summands.
Then should shift right by C times the
summand with less order.
3. Mantissa of summands must have the
same number of digits. Insignificant zeros can
be added to the right for the fractional part.
The basic rules for adding real
numbers
4. Every summands are represent in Invert or
Complement modified code. Added insignificant
zeros change their significance with
transformations according to the general rule.
5. Bit of sign take part in an add operation as too
as the others bits.
6. When using a invert code if we have a carry
bit is 1 from the highest bit we should to add this
value to the low bit.
7. When using a complement format carry bit is
lost.
The basic rules for adding real
numbers
8. The result of a sign is generated
automatically
9. The result of adding is represented in the
code of summands.
10.If the digits in the sign digits are
different, it's overflow of a bit grid. We need
to perform SAR this sum by one bit right
(due to we don’t use the machines format
for representation the digits, in our
examples the bit grid is increasing by an
one bit and a value of a most sign bit is
The basic rules for adding real
numbers
11.If the highest bit of the mantissa
isn’t 1 we need to shift our sum by one
bit left and decrease the order of the
sum. We must perform this operation
until the highest bit of the mantissa
will be 1.
12.For checking, the sum is converted
into the direct code.
Example 2. Part 1.
A = 37.5 and B = 16.6.
Perform the operation C = A +B.
A2 = 100101.1. Order oa = 610 = 1102.
B2 ≈ 10000.10011 . Orde ob = 510 = 1012.
A and B in the floating-point format have next
representation:
A2 = 0 110 0 1001011
B2 = 0 101 0 1000010011
Example 2. Part 2.
A2 = 0 110 0 1001011
B2 = 0 101 0 1000010011
oa - ob = 1
The power of number of the summands is
different, so it is necessary to align the bit grid of
the mantises.
For our case, the difference of orders is equal
to 1, so the mantissa of the number B is shifted
by 1 bit to the right, and the order of the number
B is increased by 1:
B2 = 0 110 0 01000010011. ob = 610 = 1102.
Example 2. Part 3.
Mantissas don’t have the same number of the
bits. Insignificant zeros shoul be added to the
right for the fractional part.
ma = 0 10010110000
mb = 0 01000010011
Represent the summands in the modified
complement codes and perform the addition
operation:
ma = 00.10010110000
mb = 00.01000010011
mc = 00.11011000011
Example 2. Part 4.
C2 = 0 110 0 11011000011 pb = 610 = 1102.
C2 =110110.00011
To check up, convert number C2 into decimal code:
C10 = 1*25+1*24+0*23+1*22+1*21+0*20+0*2-
1+0*2-2+0*2-3+1*2-4+1*2-5 =

=32+16+4+2+0,0625+0.0313 = 54.09375
We expected C10 =54.1. But since only 6 bits were
used to the fractional part, the result contains an
error. Relative error is about 6%.
Thanks for your attention

Anda mungkin juga menyukai