Professional Documents
Culture Documents
Solution 4.a Basic Int Arithmetic v.4
Solution 4.a Basic Int Arithmetic v.4
Solution 4.a Basic Int Arithmetic v.4
65534 65535 0 +1 +2
+32768 +32767
8000 7FFF
2. Signed integer arithmetic: write a single word integer addition program using Mano’s CPU. Try it
with different numbers (32767, -32768, etc.):
signed short int X = -1;
signed short int Y = 1;
signed short int R;
R = X + Y;
Answer the following questions:
a) What is the range of values that should be assigned to X and Y?
-32768 32,767 or in Hex: 8000 7FFF
b) How is the result R interpreted? With signed integer arithmetic we can have overflow as with
unsigned integers, but also underflow as the result of adding 2 negative numbers.
We use the most significant bit to determine whether the result is bigger than smaller than 0.
a. If Result msb = 0 - it is a positive number and its magnitude between:
0 +32,767 in Hex: 0 – 7FFF
b. If Result msb = 1 - it is a negative number. Use the 2's complement method to convert it
to its positive equivalent to determine its magnitude:
(-32,768 -1 in Hex: 8000 FFFF)
8000 7FFF
-32768 +32767
Overflow
© Dr Yigal Hoffner 2 Sunday, 03 April 2022
Computer organisation and programming course, Shenkar College of Design & Engineering
3. Unsigned & Signed integer arithmetic: compare the results of doing addition in (2) & (3) – what is
happening? What is the difference between the two cases?
The result FFFF has to be interpreted in the right context!
The programmer determines the context when she decides whether we are dealing with signed or
unsigned integers. The result has to be interpreted accordingly.
LDA X
ADD Y
FFFE hex STA R
0001 hex
FFFF hex
Must be interpreted as Must be interpreted as