The Solution manual of COAL
Chapter NO 4. exercise
if anyone has Questions Regarding this exercise.
contact me on my given Email-ID.
i will guide you. Thank you!
Rapple "Scholarly Communications and the Sustainable Development Goals"
Introduction to ibm pc assembly language
1. A solution manual to
Assembly language
Programming
and the organization of
the IBM PC
Chapter 4
Introduction to IBM PC Assembly language
BY:- Ytha Yu & Charles Marut
prepared by :
Warda Aziz
Wardaaziz555@gmail.com
2. Question 1:
Which of the following names are legal in IBM PC assembly language?
Names Status
TWO_WORDS Legal
?1 Legal
Two words illegal
.@? illegal
$145 legal
Let’s_go illegal
T= illegal
Question 2:
Which of the following names are legal numbers? If they are legal , tell whether they
are binary , decimal or hex?
Numbers Status
246 decimal
246h hex
1001 decimal
1,101 illegal
2A3h hex
FFFEh illegal
0Ah hex
Bh illegal
1110B binary
Question 3:
If it is legal, give data definition pseudo-ops to define each of the following .
a) A word variable A initialized to 52
b) A word variable WORD1 uninitialized.
c) A byte variable B initialized to 25h
d) A byte variable C1, uninitialized
e) A word variable WORD1, initialized to 65536
f) A word array ARRAY1, initialized to the first five positive integers
g) A constant BELL equal to 07h
h) a constant message equal to ‘THIS IS A MESSAGE$’
Solution:
A word variable A initialized to 52
A DW 52
A word variable WORD1 uninitialized.
WORD1 DW ?
A byte variable B initialized to 25h
B DB25h
A byte variable C1, uninitialized
C1 DB ?
A word variable WORD1, initialized to 65536
3. WORD1 DW 65536
A word array ARRAY1, initialized to the first five positive integers
ARRAY1 DW 1,2,3,4,5
A constant BELL equal to 07h
BELL EQU 07h
A constant message equal to ‘THIS IS A MESSAGE$’
MSG EQU ‘THIS IS A MESSAGE$’
Question 4:
Suppose that the following data are loaded starting at offset 0000h
A DB 7
B DW 1ABCh
C DB ‘HELLO’
a. Give the offset address assigned to variables A,B and C
b. Give the contents of the byte at offset 0002h in hex
c. Give the contents of the byte at offset 0004h in hex
d. Give the offset address of the character “O” in “HELLO”
variable content Address
A 7 0000
B BC 0001
1A 0002
C H 0003
E 0004
L 0005
L 0006
0 007
A) A: 0000
B: 0001
C: 0003
B) 1A
C) E
D)0007
Question 4:
Tell whether each of the instructions is legal or illegal
instruction status
MOV DS,AX Legal
MOV DS, 1000h Illegal ;can’t use seg register with an
immediate value
MOV CS,ES Illegal; seg registers cannot go together
MOV W1, DS Legal
XCHG W1,W2 Illegal
SUB 5, B1 Illegal
ADD B1,B2 illegal
ADD AL, 256 illegal
MOV W1,B1 Illegal
Question 6:
Using only MOV , ADD, SUB, INC, DEC and NEG , translate the following high
level language assignment statements into assembly language A,B and C are word
variables.
4. A) A=B-A
B) A=-(A+1)
C) C=A+B
D) B=3*B+7
E) A=B-A-1
A=B-A
MOV AX, a
MOV BX, b
SUB BX,AX
MOV AX,BX
A=-(A+1)
MOV AX,A
ADD AX,1
NEG AX
MOV A,AX
C=A+B
MOV AX,A
ADD AX,B
MOV C,AX
B=3*B+7
MOV AX,B
ADD AX,B
ADD AX,B
ADD AX,7
MOV B,AX
A=B-A-1
MOV BX,B
SUB BX,A
SUB BX,1
MOV A, BX
Question 7:
Write instructions to do the following.
A. Read a character and display it at the next position on the same line
B. Read an uppercase letter and display it at the next position on the same line in lower
case
Read a character and display it at the next position on the same line
mov ah,1
int 21h
mov ah,2
mov dl,al
int 21h
Read an uppercase letter and display it at the next position on the same line in lower
case
mov ah,1
int 21h
add al,20h
mov ah,2
mov dl,al
int 21h
5. Question 8:
Write a program to
a) display a “?”
b) read two decimal digits whose sum is less than 10
c)display them and their sum in the next line with an appropriate message.
Code:
.MODEL SMALL
.STACK 100H
.DATA
MSG DB 0AH, 0DH, "The sum of "
VAR DB ?, ' and '
var2 DB ? , ' is ';
sum DB ?,"$"
.CODE
MAIN PROC
;DATA INITIALIZATION
MOV AX, @DATA
MOV DS, AX
; DISPLAY ? TO PROMPT THE USER FOR INPUT
MOV AH, 2
MOV DL, '?'
INT 21H
;READ DECIMAL DIGITS
MOV AH, 1
INT 21H
MOV VAR, AL ; storing var in another reg
;INPUT 2ND VARIABLE
INT 21H ; storing VAR2 in AL
MOV var2, AL
;ADDING VARIABLES
ADD AL, VAR
SUB AL, 30H ;there is ASCII coding in background so subtracting code 30h
MOV SUM , AL
;DISPLAY MSG
LEA DX, MSG
MOV AH, 9
INT 21H
;DOS EXIT
MOV AH, 4CH
INT 21H
MAIN ENDP
END MAIN
Output:
Question 9:
write a program to
A) prompt the user
B) Read first middle and last initials of a person’s name
C) And display them down the left margin
6. Ans:
.MODEL SMALL
.STACK 100H
.DATA
MSG DB 0AH, 0DH,, "Enter three initials:$"
A DB ?
b DB ?
c DB ?
.CODE
MAIN PROC
MOV AX, @DATA
MOV DS, AX
;DISPLAYING LINES
LEA DX, MSG
MOV AH, 9
INT 21H
;TAKING INPUT
MOV AH, 1 ;First input
INT 21H
MOV A, AL
INT 21H ;Second input
MOV B, AL
INT 21H ;3rd input
MOV C, AL
;LINE FEED
MOV AH,2
MOV DL, 0AH
INT 21H
MOV DL, 0DH
INT 21H
;display function
MOV AH, 2
MOV DL, A
INT 21H
;LINE FEED
MOV AH,2
MOV DL, 0AH
INT 21H
MOV DL, 0DH
INT 21H
;DISPLAY 2ND NUM
MOV AH, 2
MOV DL, B
INT 21H
;LINE FEED
MOV AH,2
MOV DL, 0AH
7. INT 21H
MOV DL, 0DH
INT 21H
;DISPLAY
MOV AH, 2
MOV DL, C
INT 21H
; DOS EXIT
MOV AH, 4CH
INT 21H
MAIN ENDP
END MAIN
Output:
Q 10:
Write a program to read one of the hex digits A-F;and display it on the next line in
decimal.
Ans:
.MODEL small
.STACK 100h
.DATA
MSG DB 'enter a hex digit'
C db ?, '$'
MSG2 DB 0AH,0DH,"In decimal it is: 1"
C2 db ?,'$'
MAIN PROC
MOV AX, @DATA
MOV DS,AX
;Displaying first message
MOV AH, 9
LEA DX, MSG
INT 21H
;input
MOV AH,1
INT 21H
8. MOV C, AL
;CALCULATION
SUB AL, 11H
MOV C2,AL
;DISPLAY
MOV AH,9
LEA DX, MSG2
INT 21H
;DOS EXIT
MOV AH, 4CH
INT 21H
MAIN ENDP
END MAIN
Output:
Question 11:
write a program to display a 10*10 solid box of asterisk.
Hint: declare a string in the data segment that specifies the box and display it with INT
21h function 9h.
Ans:
.MODEL SMALL
.STACK 100H
.DATA
MSG DW 0AH,0DH,'**********$'
.CODE
MAIN PROC
MOV AX, @DATA
MOV DS, AX
;FUNCTION 9 FOR DISPLAYING OUTPUT STRING
MOV AH,9
LEA DX ,MSG
INT 21H ;OUTPUT FOR first line
INT 21H ;output for second line
INT 21H ; .
INT 21H ; .
INT 21H ; .
INT 21H ; .
INT 21H ; .
INT 21H ; .
INT 21H ; .
INT 21H ; output for the 10th line
;DOS EXIT
MOV AH, 4CH
INT 21H
MAIN ENDP
END MAIN
9. Output:
Write a program to display
a) ?
b) Read three initials
c) Display them in the middle of an 11*11 box of asterisk
d) Beep the computer
Ans:
.STACK 100h
.MODEL small
.DATA
msg DB "?$"
msg1 DB 0Ah, 0Dh,"**********$"
msg2 DB 0Ah, 0Dh,"***"
ch1 DB ?
ch2 DB ?
ch3 DB ?,"****$"
.CODE
main PROC
MOV AX, @DATA
MOV DS, AX
;prompt the user for ?
MOV AH,2
MOV DL, msg
INT 21h
;enter initials
MOV AH,1
int 21h
MOV ch1, AL
INT 21h
MOV ch2, AL
INT 21h
MOV ch3, AL
; output
MOV AH,9
lea DX, msg1
INT 21h
INT 21h
INT 21h
INT 21h
10. INT 21h
INT 21h
LEA DX, msg2
INT 21h
LEA DX, msg1
INT 21h
INT 21h
INT 21h
INT 21h
INT 21h
;BEEP THE COUNTER
MOV AH, 2
MOV DL, 7H
INT 21H
;dos exit
MOV AH, 4Ch
INT 21h
main ENDP
END main
Output