In: Computer Science
Assuming signed two’s complement representation using m=8 bits, add the following numbers using binary addition AND determine the values of the N, Z, V and C flags in response to each calculation.
(-128) + (+100)
(+5) + (+7)
(+5) + (-7)
(-5) + (+7)
(-5) + (-7)
(+120) + (+100)
(-120) + (-100)
(6A)16+ (E2)16
(A7)16+ (35)16
(80)16+ (80)16
Now let's find each number in signed 2's complement representation. For positive numbers we just need to find it's signed 1's complement. For negative number we need to add 1 to the signed 1's complement.
i
Now +100 = 0110 0100
-128 = 1000 0000. Hence the result will be 1110 0100.
ii
+5 = 0000 0101
+7 = 0000 0111
Result = 0000 1100
iii Here -7 = 1111 1001 and +5 = 0000 0101 hence result = 1111 1110
iv
-5 = 1111 1011
+7 = 0000 0111
result = 1 0000 0010 ( Overflow will occur)
v
-5 + -7 = 1111 1011 + 1111 1001 = 1 1111 0100 (Overflow will occur)
vi
120 + 100 = 0111 1000 + 0110 0100 = 1101 1100 . Result got negative because range of +127 exceeded.
vii
Now -120 + -100 = 1000 1000 + 1001 1100 = 1 0010 0100 (Overflow)
viii
6A + E2 = 0110 1010 + 1110 0010 = 1 0100 1100 (Overflow)
ix
A7 + 35 = 1110 0010 + 0011 0101 = 1 0001 0111 (Overflow)
x
80+80 = 1000 0000 + 1000 0000 = 1 0000 0000 (Overflow and Zero Result)
Now we will indicate the status of flags (N,Z,V,C) for all of the above . Note the order of bits below correspond to order in (NZVC)
i . (1000)
ii (0000)
iii (1000)
iv (0010)
v (1010)
vi (1000)
vii (0010)
viii (0010)
ix (0010)
x (0110)