ICS 233 Homework Assignment 01 – Term 191
Due: 11:59 pm on Thursday, 19th September 2019
Instructions: Submit in the common ICS 233 Blackboard a .zip file containing:
A word or pdf document containing the solutions for Questions 1 to 11.
[Note: handwritten submissions must be neat and legible]
The assembly language file (.asm) and its associated .vcxproj file [Note: DON’T SUBMIT THE
ENTIRE PROJECT, specifically DON’T SUBMIT .exe files]
The submitted .zip file must be named in the format:
LectureSection#HW01_KFUPMID_FamilyName.zip
Example:
01_HW01_201900020_AlDossary.zip
1. Compute the final result of each of the following unsigned operations and for each determine whether there
is unsigned overflow or not. Give reasons for each of your answer. Note: For each question, perform the
calculations in the given base (binary, decimal or hexadecimal).
(a) 00111111B + 01111110B (8-bit operands)
00111111
01111110 +
=======
10111101
No Overflow
(b) DD91H + 7ECEH (16-bit operands)
DD91
7ECE +
======
15C5F --- Overflow, more 4-bit than 16-bit
(c) EA9BH – F2DEH (16-bit operands)
EA9B
F2DE -
======
(b) F7BD unsatisfied borrow, so we have Overflow
(d) 5672110 + 3246210 (16-bit operands)
First we count the limit of Overflow in decimal which is
2216 − 1 = 65535
56721
32462 +
======
89183 Overflow
Because the limit of 16-bit operands equals 65535 in decimal and the result equal 89183
Which means 89183 > 65535 so we have overflow here
Page 1 of 7
(e) DB7EH + FEF6H (16-bit operands)
DB7E
FEF6 +
======
1DA74 Overflow, more 4-bit than 16-bit
2. Compute the final result of each of the following signed r’s complement operations and for each determine
whether the operation will result in signed overflow or not. Show your steps, and give reason for your answer.
(a) 0111 0111B + 1110 1110B (8-bit operands)
01110111
11101110 +
=========
101100101 the result in 9-bit which means Overflow
(b) 59EFH + 62CAH (16-bit operands)
(+ve) 59EF
(+ve) 62CA +
======
(-ve) BCB9 Overflow, because the result has different sign
(c) 7C02H - FBDAH (16-bit operands)
First we have to convert “FBDA” to 1’s complement “ CHECK HERE “
FFFF
FBDA –
======
0426 this is the r’s complement of “FBDA”
(+ve) 7C02
(+ve) 0426 +
=====
(-ve) 8028 Overflow, because the result has different sign
Page 2 of 7
(d) 124EH – 74ADH (16-bit operands)
First we have to convert “74AD” to r’s complement “ CHECK HERE “
FFFF
74AD –
======
8B53 this is the r’s complement of “74AD”
(+ve) 124E
(-ve) 8B53 +
=====
(-ve) 9DA1
No Overflow, because we add different sign Hex number
3. Express the negative value -25 as a 2's complement integer, using eight bits. Repeat it for 16 bits and 32 bits.
What does this illustrate with respect to the properties of sign extension as they pertain to 2's complement
representation?
A) First : convert 25 to binary using 8-bit
25 => 00011001
Second : covert each 1 to 0 and vica varsa
11100110 this is 1’s complement of -25
Third : add one to the result to get the 2’s complent
11100111 this is 2’s complement of -25 in 8-bit
B) By using sign extention method we can easily express -25 as a 2’s complement integer
by adding the most significant bit to the left
1111111111100111 this is 2’s complement of -25 in 16-bit
C) By using sign extention method we can easily express -25 as a 2’s complement integer
by adding the most significant bit to the left
11111111111111111111111111100111 this is 2’s complement of -25 in 32-bit
4. Convert the floating-point number -114.625 into:
Step 1:
Sign = 1 because it’s a negative number
Step 2: convert the number to binary
114.625 1110010.101 1.110010101× 26
Fraction = 110010101
(a) 32-bit IEEE 754 representation in hexadecimal.
Exponent of binary32 127 + 6 = 133 = 10000101
-114.625 equal in 32-bit IEEE 754 representation 1 10000101 11001010100000000000000
Now we have to convert in hexadecimal
1100 0010 1110 0101 0100 0000 0000 0000
C 2 E 5 4 0 0 0
The result is C2E54000
Page 3 of 7
(b) 64-bit IEEE 754 representation in hexadecimal
Exponent of binary64 1023 + 6 = 1029 = 10000000101
1100 0000 0101 1100 1010 1000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000
C 0 5 C A 8 0 0 0 0 0 0 0 0 0 0
The result is C05CA80000000000
(c) 80-bit IEEE 754 x86 extended-precision representation in hexadecimal
Exponent of binary80 16383 + 6 = 16389 = 1000 0000 0000 101
1100 0000 0000 0101 1100 1010 1000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000
C 0 0 5 C A 8 0 0 0 0 0 0 0 0 0 0 0 0 0
The result is C005CA80000000000000
5. Convert the floating-point number 85.45 into 32-bit IEEE 754 floating-point representation in hexadecimal.
Show all steps and computations.
STEP I:- convert 85.45 to binary
1010101.01110011001100 // 1100 repeated it self recursively
STEP II:-
1.0101010111001100×26
STEP III:-
E = 6 + 127 = 133 = 1000 0101
M = 01010101110011001100110
S = +ve = 0
0 1000 0101 01010101110011001100110
S E M
STEP IV :- transfer to hexdecimal form
0100 0010 1010 1010 1110 0110 0110 0110
4 2 A A E 6 6 6
Result is :- 42AAE666
Page 4 of 7
6. Convert the IEEE 754 floating-point representation 88888000H into decimal. Your final answer must be in
the form ±1.xxx . . . x * 2n Show all steps and computations.
STEP I :- Express the number in binary
88888000
1 00010001 00010001000000000000000
STEP II :- Find the actual exponent
E = 00010001 = 17
n = 17 – 127 = -110
S=1
M = 00010001000000000000000
STEP III :- put S,M and n together to form binary result
The Result : -1.00010001×2−110
7. Convert the IEEE 754 floating-point representation C378C000H into decimal. Show all steps and computations.
STEP I :- express the number in binary
C378C000
1 10000110 11110001100000000000000
STEP II :- Find the actual exponent
E = 10000110 =134
n = 134 – 127 = 7
S=1
M = 11110001100000000000000
STEP III :- put S,M and n together to form binary result
-1.111100011×27 = -11111000.11
The Result : -120.75
8. Convert the IEEE 754 floating-point representation FF800000H into decimal. Show all steps and computations.
STEP I :- express the number in binary
FF800000
1 11111111 00000000000000000000000
STEP II :-
E = 11111111 = 255
For E = 255 , N represents special values, such as ±∞ or NaN
In or case because of Mantissa = 0 , Exponent = 255 , Sign = 1 (-ve)
So, FF800000 = -∞
Page 5 of 7
9. Convert the IEEE 754 floating-point representation 00600000H into decimal. Show all steps and computations.
STEP I :- express the number in binary
00600000
0 00000000 11000000000000000000000000
STEP II :-
E = 00000000 = 0
N = -126 , because it is denormalized number
S=0
M = 1100
STEP III :- put S, M and n together to form binary result
Denormalized form : (−1)𝑆 ×0.M×2−126
+0.11×2−126
+0.75×2−126
Let’s transfer 2−126 to base 10
10𝑥 = 2−126
x = -126 log(2)
x = - 38
The result : +0.75 × 10−38
10. Convert the IEEE 754 floating-point representation FFAB0000H into decimal. Show all steps and computations.
STEP I :- convert the Hex to binary
FFAB0000
1 11111111 01010110000000000000000
STEP II :-
E = 11111111 = 255
For E = 255 , N represents special values, such as ±∞ or ±NaN
In or case because of Mantissa = 01010110000000000000000 , Exponent = 255 , Sign = 1 (-ve)
So, FFAB0000 = -NaN
Page 6 of 7
11. What decimal number does the IEEE 754 hexadecimal representation D01D600000000000H of a
double value represent? Show all steps and computations.
STEP I :- express hex number in binary
D01D 6000 0000 0000
1 10100000001 1101011000000000000000000000000000000000000000000000
STEP II :- find the actual exponent
E = 10100000001 = 1281
n = 1281 – 1023 = 258
S=1
M = 1101011000000000000000000000000000000000000000000000
STEP III :- put S,M and n together to form binary result
-1.11010110×2258 = -1.8359375×2258
10𝑥 = 2258
X = 258 log(2)
X = 78
The result : -1.8359375×1078
12. Convert the following C program into:
(a) A 32-bit x86-64 assembly language program.
(b) A 64-bit x86-64 assembly language program.
#include <stdio.h>
#include <math.h>
int main(void) {
double side1, side2, hypotenuse;
printf_s("Enter side1 and side2[cm]: ");
scanf_s("%lf%lf", &side1, &side2);
hypotenuse = sqrt(side1 * side1 + side2 * side2);
printf_s("Hypotenuse = %0.2lf cm\n", hypotenuse);
return 0;
}
Sample program runs:
Page 7 of 7