SlideShare a Scribd company logo
1 of 10
Download to read offline
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
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
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.
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
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
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
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
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
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
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

More Related Content

What's hot

What's hot (20)

Assembly Language Programming By Ytha Yu, Charles Marut Chap 7 (Logic, Shift,...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 7 (Logic, Shift,...Assembly Language Programming By Ytha Yu, Charles Marut Chap 7 (Logic, Shift,...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 7 (Logic, Shift,...
 
Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction ...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction ...Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction ...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction ...
 
Assembly Language Programming By Ytha Yu, Charles Marut Chap 5 (The Processor...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 5 (The Processor...Assembly Language Programming By Ytha Yu, Charles Marut Chap 5 (The Processor...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 5 (The Processor...
 
Binary and hex input/output (in 8086 assembuly langyage)
Binary and hex input/output (in 8086 assembuly langyage)Binary and hex input/output (in 8086 assembuly langyage)
Binary and hex input/output (in 8086 assembuly langyage)
 
Assembly language (coal)
Assembly language (coal)Assembly language (coal)
Assembly language (coal)
 
Instruction set of 8086
Instruction set of 8086Instruction set of 8086
Instruction set of 8086
 
Solution manual of assembly language programming and organization of the ibm ...
Solution manual of assembly language programming and organization of the ibm ...Solution manual of assembly language programming and organization of the ibm ...
Solution manual of assembly language programming and organization of the ibm ...
 
8086 instructions
8086 instructions8086 instructions
8086 instructions
 
Assignment on alp
Assignment on alpAssignment on alp
Assignment on alp
 
Instruction formats-in-8086
Instruction formats-in-8086Instruction formats-in-8086
Instruction formats-in-8086
 
Assembly Language Programming By Ytha Yu, Charles Marut Chap 10 ( Arrays and ...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 10 ( Arrays and ...Assembly Language Programming By Ytha Yu, Charles Marut Chap 10 ( Arrays and ...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 10 ( Arrays and ...
 
Multiplication & division instructions microprocessor 8086
Multiplication & division instructions microprocessor 8086Multiplication & division instructions microprocessor 8086
Multiplication & division instructions microprocessor 8086
 
assembly language programming organization of IBM PC chapter 9 part-1(MULTIPL...
assembly language programming organization of IBM PC chapter 9 part-1(MULTIPL...assembly language programming organization of IBM PC chapter 9 part-1(MULTIPL...
assembly language programming organization of IBM PC chapter 9 part-1(MULTIPL...
 
Assembly Language Programming By Ytha Yu, Charles Marut Chap 6 (Flow Control ...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 6 (Flow Control ...Assembly Language Programming By Ytha Yu, Charles Marut Chap 6 (Flow Control ...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 6 (Flow Control ...
 
Assembly Language Lecture 3
Assembly Language Lecture 3Assembly Language Lecture 3
Assembly Language Lecture 3
 
Flag Registers (Assembly Language)
Flag Registers (Assembly Language)Flag Registers (Assembly Language)
Flag Registers (Assembly Language)
 
8085 assembly language programming
8085 assembly language programming8085 assembly language programming
8085 assembly language programming
 
bubble sorting of an array in 8086 assembly language
bubble sorting of an array in 8086 assembly languagebubble sorting of an array in 8086 assembly language
bubble sorting of an array in 8086 assembly language
 
Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction ...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction ...Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction ...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction ...
 
8086 microprocessor lab manual
8086 microprocessor lab manual8086 microprocessor lab manual
8086 microprocessor lab manual
 

Similar to Introduction to ibm pc assembly language

Home works summary.pptx
Home works summary.pptxHome works summary.pptx
Home works summary.pptx
HebaEng
 
1) (a) Write a code fragment which adds the 32-bit contents of $8100.pdf
1) (a) Write a code fragment which adds the 32-bit contents of $8100.pdf1) (a) Write a code fragment which adds the 32-bit contents of $8100.pdf
1) (a) Write a code fragment which adds the 32-bit contents of $8100.pdf
aromanets
 
Keyboard interrupt
Keyboard interruptKeyboard interrupt
Keyboard interrupt
Tech_MX
 
Genius it ians™ 8085 programming (part 2)
Genius it ians™  8085 programming (part 2)Genius it ians™  8085 programming (part 2)
Genius it ians™ 8085 programming (part 2)
Manoj Shahu
 

Similar to Introduction to ibm pc assembly language (20)

Home works summary.pptx
Home works summary.pptxHome works summary.pptx
Home works summary.pptx
 
Assembly language programs 2
Assembly language programs 2Assembly language programs 2
Assembly language programs 2
 
Lab report assembly
Lab report assemblyLab report assembly
Lab report assembly
 
Assembly language programs
Assembly language programsAssembly language programs
Assembly language programs
 
Mcs 17 solved assignment 2015- 16
Mcs 17 solved assignment 2015- 16Mcs 17 solved assignment 2015- 16
Mcs 17 solved assignment 2015- 16
 
Exp 03
Exp 03Exp 03
Exp 03
 
Emulador emu8086
Emulador emu8086Emulador emu8086
Emulador emu8086
 
جميع اوامر لغة الاسمبلي
جميع اوامر لغة الاسمبلي جميع اوامر لغة الاسمبلي
جميع اوامر لغة الاسمبلي
 
Compiladores emu8086
Compiladores emu8086Compiladores emu8086
Compiladores emu8086
 
1) (a) Write a code fragment which adds the 32-bit contents of $8100.pdf
1) (a) Write a code fragment which adds the 32-bit contents of $8100.pdf1) (a) Write a code fragment which adds the 32-bit contents of $8100.pdf
1) (a) Write a code fragment which adds the 32-bit contents of $8100.pdf
 
Code Conversion in 8085 Microprocessor
Code Conversion in 8085 MicroprocessorCode Conversion in 8085 Microprocessor
Code Conversion in 8085 Microprocessor
 
Microprocessor and micro-controller lab (assembly programming)
Microprocessor and micro-controller lab (assembly programming)Microprocessor and micro-controller lab (assembly programming)
Microprocessor and micro-controller lab (assembly programming)
 
Keyboard interrupt
Keyboard interruptKeyboard interrupt
Keyboard interrupt
 
Genius it ians™ 8085 programming (part 2)
Genius it ians™  8085 programming (part 2)Genius it ians™  8085 programming (part 2)
Genius it ians™ 8085 programming (part 2)
 
Assembly language solution
Assembly language  solutionAssembly language  solution
Assembly language solution
 
Microprocessor 8086-lab-mannual
Microprocessor 8086-lab-mannualMicroprocessor 8086-lab-mannual
Microprocessor 8086-lab-mannual
 
Taller practico emu8086_galarraga
Taller practico emu8086_galarragaTaller practico emu8086_galarraga
Taller practico emu8086_galarraga
 
Assembly Language Basics
Assembly Language BasicsAssembly Language Basics
Assembly Language Basics
 
Bcsl 022 solved-assignment_2012-13
Bcsl 022 solved-assignment_2012-13Bcsl 022 solved-assignment_2012-13
Bcsl 022 solved-assignment_2012-13
 
Class 12 computer sample paper with answers
Class 12 computer sample paper with answersClass 12 computer sample paper with answers
Class 12 computer sample paper with answers
 

Recently uploaded

ppt your views.ppt your views of your college in your eyes
ppt your views.ppt your views of your college in your eyesppt your views.ppt your views of your college in your eyes
ppt your views.ppt your views of your college in your eyes
ashishpaul799
 
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
中 央社
 

Recently uploaded (20)

Danh sách HSG Bộ môn cấp trường - Cấp THPT.pdf
Danh sách HSG Bộ môn cấp trường - Cấp THPT.pdfDanh sách HSG Bộ môn cấp trường - Cấp THPT.pdf
Danh sách HSG Bộ môn cấp trường - Cấp THPT.pdf
 
ppt your views.ppt your views of your college in your eyes
ppt your views.ppt your views of your college in your eyesppt your views.ppt your views of your college in your eyes
ppt your views.ppt your views of your college in your eyes
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT VẬT LÝ 2024 - TỪ CÁC TRƯỜNG, TRƯ...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT VẬT LÝ 2024 - TỪ CÁC TRƯỜNG, TRƯ...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT VẬT LÝ 2024 - TỪ CÁC TRƯỜNG, TRƯ...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT VẬT LÝ 2024 - TỪ CÁC TRƯỜNG, TRƯ...
 
Word Stress rules esl .pptx
Word Stress rules esl               .pptxWord Stress rules esl               .pptx
Word Stress rules esl .pptx
 
How to the fix Attribute Error in odoo 17
How to the fix Attribute Error in odoo 17How to the fix Attribute Error in odoo 17
How to the fix Attribute Error in odoo 17
 
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
 
“O BEIJO” EM ARTE .
“O BEIJO” EM ARTE                       .“O BEIJO” EM ARTE                       .
“O BEIJO” EM ARTE .
 
Telling Your Story_ Simple Steps to Build Your Nonprofit's Brand Webinar.pdf
Telling Your Story_ Simple Steps to Build Your Nonprofit's Brand Webinar.pdfTelling Your Story_ Simple Steps to Build Your Nonprofit's Brand Webinar.pdf
Telling Your Story_ Simple Steps to Build Your Nonprofit's Brand Webinar.pdf
 
INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdf
INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdfINU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdf
INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdf
 
Features of Video Calls in the Discuss Module in Odoo 17
Features of Video Calls in the Discuss Module in Odoo 17Features of Video Calls in the Discuss Module in Odoo 17
Features of Video Calls in the Discuss Module in Odoo 17
 
Morse OER Some Benefits and Challenges.pptx
Morse OER Some Benefits and Challenges.pptxMorse OER Some Benefits and Challenges.pptx
Morse OER Some Benefits and Challenges.pptx
 
Application of Matrices in real life. Presentation on application of matrices
Application of Matrices in real life. Presentation on application of matricesApplication of Matrices in real life. Presentation on application of matrices
Application of Matrices in real life. Presentation on application of matrices
 
Operations Management - Book1.p - Dr. Abdulfatah A. Salem
Operations Management - Book1.p  - Dr. Abdulfatah A. SalemOperations Management - Book1.p  - Dr. Abdulfatah A. Salem
Operations Management - Book1.p - Dr. Abdulfatah A. Salem
 
Keeping Your Information Safe with Centralized Security Services
Keeping Your Information Safe with Centralized Security ServicesKeeping Your Information Safe with Centralized Security Services
Keeping Your Information Safe with Centralized Security Services
 
B.ed spl. HI pdusu exam paper-2023-24.pdf
B.ed spl. HI pdusu exam paper-2023-24.pdfB.ed spl. HI pdusu exam paper-2023-24.pdf
B.ed spl. HI pdusu exam paper-2023-24.pdf
 
Gyanartha SciBizTech Quiz slideshare.pptx
Gyanartha SciBizTech Quiz slideshare.pptxGyanartha SciBizTech Quiz slideshare.pptx
Gyanartha SciBizTech Quiz slideshare.pptx
 
UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...
UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...
UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...
 
size separation d pharm 1st year pharmaceutics
size separation d pharm 1st year pharmaceuticssize separation d pharm 1st year pharmaceutics
size separation d pharm 1st year pharmaceutics
 
slides CapTechTalks Webinar May 2024 Alexander Perry.pptx
slides CapTechTalks Webinar May 2024 Alexander Perry.pptxslides CapTechTalks Webinar May 2024 Alexander Perry.pptx
slides CapTechTalks Webinar May 2024 Alexander Perry.pptx
 
MichaelStarkes_UncutGemsProjectSummary.pdf
MichaelStarkes_UncutGemsProjectSummary.pdfMichaelStarkes_UncutGemsProjectSummary.pdf
MichaelStarkes_UncutGemsProjectSummary.pdf
 

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