You are on page 1of 8

A solution manual to

Assembly language
Programming
and the organization of
the IBM PC

Chapter 2
Representation of numbers and
characters

BY:- Ytha Yu & Charles Marut


prepared by :
Warda Aziz
Wardaaziz555@gmail.com
Question 1:
In many applications , it saves time to memorize the conversions
among small binary, decimal, and hex numbers. Without referring to
the table , fill in the blanks in the following table
binary decimal hex
1001 9 9
1010 10 A
1101 13 D
1100 12 C
1110 14 E
1011 11 B

Question 2:
Convert the following numbers into decimal:
A) 1110
B) 100101011101
C) 46Ah
D) FAE2Ch
Solution:
1110:
=1*23 + 1*22 + 1*21 + 0*20
=8 + 4 + 2 + 0
=14
100101011101:
=(1*211)+(0*210)+(0*29)+(1*28)+(0*27)+(1*26)+(0*25)+(1*24)+(1*23)+(1*22)+(0
*21) +(1*2 0)
=2048 + 0 + 0 + 256 + 0 + 64 + 0 + 16 + 8 +
4 + 0 +1
2397
46Ah:
=4*162 + 6*161 + A*160
=4*256+ 6*16 +10*1
=1024 + 96 +10
=1130
FAE2Ch:
=F*164 + A* 163 + E*162 + 2*161 +C*160
=15*65536 + 10* 4096 + 14*256 +2*16 +12*1
=983040 + 40960 +3584 +32+12
=1027628

Question 3:
Convert the following decimal numbers:
a) 97 to binary
b) 627 to binary
c) 921 to hex
d) 6120 to hex
Solution:
97 to binary
;LCM with 2, remaining bits are in binary

=1110 0001
627 to binary
=0010 0111 0011
921 to hex
LCM with 16, remaining digits are in hex form
=399
6120 to hex
=17E8

Question 4:
Convert the following numbers:
a) 1001011 to hex
b) 1001010110101110 to hex
c) A2Ch to binary
d) B34Dh to binary
Solution:
a) 1001011 to hex
1001011=0100 1011(byte complete)
As we know 0100=4 and 1011=B
=4B
b) 1001010110101110 to hex
=95AE
c) A2Ch to binary
A=10d=1010(binary)
2=0010(binary)
C=12d=1100(binary)
=1010 0010 1100b
d) B34Dh to binary
B=11(decimal)=1011(binary),
3=0011(binary)
4=0100(binary)
D=1101(binary)
=1011 0011 0100 1101b

Question 5:
Perform the following addition:
a. 100101b + 10111b
b. 100111101b + 10001111001b
c. B23CDh + 17912h
d. FEFFEh + FBCADh
Solution:
100101b + 10111b

100101
+10111
111100
100111101b + 10001111001b
 
100111101
+ 10001111001
10110110110
B23CDh + 17912h
B23CD
+17912
C9CDF
FEFFEh + FBCADh
Solving from the right most values i.e., Eh+Dh=14d+13d=27d
27d=1Bh(solving through LCM method)
B is written below and 1 is given carry to the left bit.
Process goes so on and we get;

FEFFE
+FBCAD
1FACAB

Question 6:
Perform the following subtraction:
a) 11011 - 10110
b) 10000101 - 111011
c) 5FC12h - 3ABD1h
d) F001Eh - 1FF3Fh
Solution:
11011 - 10110
11011
- 10110
00101
10000101 - 111011
10000101
- 111011
1001010
5FC12h - 3ABD1h
    ;borrow carries
0101 1111 1100 0001 0010 (5FC12h)
- 0011 1010 1011 1101 0001 (3ABD1)
0010 0101 0000 0100 0001 (binary)
=25041(hex)
F001Eh - 1FF3Fh
    
1111 0000 0000 0001 1110
- 0001 1111 1111 0011 1111
1101 0000 0000 1101 1111
=D00DF

Question 7:
Give the 16 bit representation of each of the following decimal
integers . write answers in hex.
a. 234d
b. -16d
c. 31634d
d. -32216d
Solution:
234
Bin= 0000 0000 1110 1010
Hex=00EAh
-16
Bin=0000 0000 0001 0000
2’s compliment:
 
1111 1111 1110 1111
+1
1111 1111 1111 0000
=FFF0h
Hex=FFF0h

31634
bin= 0111 1011 1001 0010b
Hex=7B92h

-32216
Same as Q7(part e)
Bin=1000 0010 0010 1000b
Hex=8228h

Question 8:
Do the following binary and hex subtractions by two’s compliment
addition.
a) 10110100b - 10010111b
b) 10001011b - 11110111b
c) FE0Fh - 12ABh
d) 1ABCh - B3EAh
Solution:
Note:
if the resulting bit has a carry 1 , neglect the carry
if the result has no carry take 2’s compliment again with a negative sign.
10110100 - 10010111
Two’s compliment= 01101000+1=01101001

10110100
+ 01101001
1 00011101
Dropping the resulting carry bit we get the answer 0001 1101b or 11101b

10001011 - 11110111
2’s compliment 11110111=00001000+1=00001001
 
1000 1011
+0000 1001
1001 0100
Taking 2’s compliment again and put a negative sign

01101011
+1
01101100
Ans -1101100

FE0Fh - 12ABh
FE0Fh - 12ABh=1111111000001111b-1001010101011b
Take 2’s compliment of 0001 0010 1010 1011b;
1110 1101 0101 0100b+1b=1110 1101 0101 0101b
   
1111 1110 0000 1111
+1110 1101 0101 0101
1 1110 1011 0110 0100
Ans: =1110 1011 0110 0100b
=EB64h
1ABCh - B3EAh
Same as Q8(3,2)
Ans: -992Eh

Question 9:
Give the signed and unsigned interpretations of each of the following
16 bit or 8 bit numbers.
a. 7FFEh
b. 8543h
c. FEh
d. 7Fh
Solution:
7FFEh
Signed: 32766 ; as the MSB is 0(in binary)
Unsigned: 32766

8543h
Signed: -31421 ; as the MSB is 1
Unsigned: 34115
FEh
Signed: -2 ; as the MSB is 1 (see table 2.4B)
Unsigned: 254
7Fh
Signed: 127 ; as the MSB is 0
Unsigned: 127

Question 10:
Show how the decimal integer -120 would be represented
a) In 16 bits
b) In 8 bits
As we know 120d=0111 1000(binary)
-120=2’s compliment
ANS:
16 bit:
(0000 0000 1000 0111)16 + 1= (1111 1111 1000 1000)16
8 bit:
(1000 0111)8 + 1= (1000 1000)8
;2’s compliment because we are solving for negative value i.e., -120

Question 11:
For each of the following numbers ,tell whether it could be stored
(a)as a 16 bit number or (b) as an 8 bit number?
a. 32767
b. -40000
c. 65536
d. 257
e. -128
ANS:
Number Bit storage
32767 16 bit
-40000 Bigger than 16 bit
65536 Bigger than 16 bit
257 16 bit
-128 both

Question 12:
For each of the following 16 bit numbers, tell whether it is positive or
negative?
ANS:
Signed number polarity
1010010010010100b negative
783E3h positive
CB33h negative
807Fh negative
9AC4h negative

Question 13:
If the character string “$12.75” is being stored in memory starting at
address 0, give the hex contents of byte 0-5.
Data string Data
$ $ 24
1 1 31
2 2 32
. . 2E
7 7 37
5 5 35
ANS: The content at address 5 is 35.

Question 14:
Translate the message of ASCII
41 74 74 61 63 6B 20 61 74 20 44 61 77 6E
ANS: Attack at Dawn

Question 15:
Suppose that a byte contains the ASCII code of an upper case letter.
What hex number should be added to it to convert it to lower case?
ANS: 20h

Question 16:
Suppose a byte contains a decimal digit that is “0”….“9” . what hex
number should be subtracted from the byte to convert it to the
numerical form of chracters?
Ans:30h

You might also like