0% found this document useful (0 votes)
7 views34 pages

4,5,6

Uploaded by

oaa777953705
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views34 pages

4,5,6

Uploaded by

oaa777953705
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 34

Chapter (4):

Bios and Dos programming in

assembly

5/11/2023 1
Chapter (4):
Outlines:
 Bios INT 10H programming: using INT 10H to:
 Clear the screen
 Set the cursor position
 others
 Dos interrupt IN 21H: using INT 21H to:
 Input character from keyboard
 Output the character to screen
 Input & output string

5/11/2023 2
Bios INT 10H
 Clearing the screen using INT 10H & function 06H:

5/11/2023 3
Bios INT 10H
 Setting the cursor to specific location using INT 10H & function 02H:

 Get current cursor position using INT 10H & function 03H:

5/11/2023 4
Dos INT 21H
 Outputting a string of data to the monitor using INT 21H & option 09:

 Outputting a single character to the monitor using INT 21H & option 02:

 Inputting a single character using INT 21H & option 01:

 Inputting a string of data from keyboard using INT 21H & option 0A:

5/11/2023 5
Dos INT 21H
TITLE FIRST: input letter from keyboard then print letter in new raw
 Example: .M ODEL SM ALL
.STACK 100H
.CODE
M A IN PROC
;display the character ‘?’
M OV AH,2
M OV DL,'?'
INT 21H
;read letter from keyboard
M OV AH,01
INT 21H
M OV BL,AL ;storage letter
M OV AH,02 ;display letter
M OV DL,0DH ;carriage return
INT 21H
M OV DL,0A H ;line feed
INT 21H
;display the input letter
M OV DL,BL
INT 21H
M OV AH,4CH
INT 21H
M A IN ENDP
END M A IN

5/11/2023 6
Dos INT 21H
TITLE THIRD: CASE CONVERSION PROGRAM (from small to capital)
 Example: .M ODEL SM ALL
.STACK 100H
.DATA
CR EQ U 0DH
LF EQ U 0AH
M SG1 DB 'ENTER A LOW ER CASE LETTER: $'
M SG2 DB CR,LF,'IN U PPER CASE IT IS:'
CHAR DB ?,'$'
.CODE
M AIN PROC
;initialize DS
M OV AX,@ DATA
M OV DS,AX
;print user prompt M OV DX,offset M SG1
LEA DX,M SG1
M OV AH,09H
INT 21H
;input character and convert to low er case
M OV AH,01H
INT 21H To convert from small to capital
SU B AL,20H
M OV CHAR,AL
;display on the next line
LEA DX,M SG2
M OV AH,09H
INT 21H
;return to DOS
M OV AH,4CH
INT 21H
M AIN ENDP
5/11/2023 END M AIN 7
Dos INT 21H
 Example:
In text file

5/11/2023 8
Dos INT 21H
 Example:

LEA DX,M ESSAGE

5/11/2023 9
Dos INT 21H
 Example:

5/11/2023 10
Dos INT 21H
 Example:

5/11/2023 11
Dos INT 21H
 Example:

5/11/2023 12
Chapter (5):
M acro and the M ouse

5/11/2023 13
Chapter (5):
Outlines:
 Define macro and how to use in assembly:
 How macro expanding by assembler:
 How to control the expanded of macro in list file:
 Define the local variable in macro:
 How to include the macro in another file:

5/11/2023 14
Macros
 M acro allow the programmer to w rite the task (set of codes perform a specific job)
once only and to invoke it w henever it is needed w herever it is needed.

 In list file the code (string message1) is expanded to:

5/11/2023 15
Macros
 Can the macro contain comments?
 The answ er is yes, but there is aw ay to suppress comments and
make the assembler show only the code only.
 If comments are preceded by (;),they w ill show up in the list file.
 If comments are preceded by (;;),they w ill not show up in the list file.
 Or using 3 directives:
 .LALL (list all): list all the instructions and the comments that are preceding
by (;) and can not list the instructions and the comments that are preceding
by (;;)
 .SALL (suppress all)
 .XALL (executable all): list only the instructions

5/11/2023 16
Macros
 Example:

5/11/2023 17
Macros
 LOCAL directive: used to define label in macro.

M U LTIPLY 2,4,RESU LT

5/11/2023 18
Macros
 LOCAL directive: used to define label in macro.

5/11/2023 19
Macros
 INCLU DE directive: allow s a programmer to w rite macros and save
them in a file (for ex. “M YM ACRO1.M AC”), and later bring them
into any file or program.

Include macro to clear


screen,set cursor and
display string

5/11/2023 20
Chapter (6):
Signed Numbers & Strings &
Tables
Lifted… …

5/11/2023 21
Chapter (6):
Outlines:
 Code string instructions:
 Explain the function of registers SI & DI in string
operation
 Explain the direction flag in string instructions
 (M OVSB,M OVSW ,STOS,LODS,CM PS,SCAS)
 Tables processing:
 XLAT
5/11/2023 22
String Operations
 U se of SI and DI,DS and ES in string instructions:
 In 8086, the SI and DI registers alw ays point to the source and
destination operands,respectively.
 To generate the physical address,alw ays uses SI as the offset of
the DS register and DI as the offset of ES register.
 By using the string instructions,they are capable of compare or
transfer or … tw o arrays of data located in memory locations
pointed at by the SI and DI registers.

5/11/2023 23
String Operations
 Byte and W ord operand in string instructions:

5/11/2023 24
String Operations
 Direction flag (DF) in string instructions:
 U sually,W e need the pointer (incremented or decremented) to
process operands located in memory locations.
 In string operations this is achieved by the direction flag (DF).
 DF is the bit 11 (D10) in the flag register (D0 – D15).
 DF is set to high or low in order to the choice of increment or
decrement the SI and DI pointers.
 By U sing the instructions:
1) CLD (clear the DF): then DF = 0, indicate the pointers should
be increment automatically (autoincrement).
2) STD (set the DF): then DF = 1, indicate the pointers should be
decrement automatically.

5/11/2023 25
String Operations
 Prefix:
 REP (repeat) prefix: allow a string instruction to repeat the
operation.(process is repeated until CX = 0).
 U sing the REP w ith string instructions M OVS,STOS,and LODS.
 REPZ (repeat zero): is the same REPE (repeat equal),w ill repeat
the string operation as long as the source and destination are
equal (ZF =1) or until CX = 0.
 REPNZ (repeat not zero): is the same REPNE (repeat not equal),
w ill repeat the string operation as long as the source and
destination are not equal (ZF =0) or until CX = 0.
 U sing the REPZ & REPNZ w ith string instructions CM PS and
SCANS.

5/11/2023 26
String Operations
 Example: (M OVSB & M OVSW )

5/11/2023 27
String Operations
 STOS & LODS instructions:
 STOSB instruction: stores the byte in AL register into
memory locations pointed at by ES:DI and increment DI
once if (DF = 0),if DF = 1,then DI is decremented once.
 STOSW instruction: stores the contents of AX register into
memory locations pointed at by ES:DI and ES:DI+1 (AL into
ES:DI and AH into ES:DI+1),then increment DI tw ice if (DF =
0),if DF = 1,then DI is decremented tw ice.
 LODSB instruction: loads the content of memory locations
pointed at by DS:SI into AL and increment SI once or
decrement SI once.
 LODSW instruction: : loads the content of memory
locations pointed at by DS:SI into AL and DS:SI+1 into AH
and increment SI tw ice or decrement SI tw ice.

5/11/2023 28
String Operations
 Example: (STOS & LODS )

5/11/2023 29
String Operations
 CM PS & SCANS instructions:
 CM PS (compare string) instruction: allow s the comparison
of tw o arrays of data pointed at by the SI and DI registers.
And depending on w hich prefix REPE or REPNE is used, a
decision is made for equality or inequality.

 SCANS (scan string) instruction: compares each byte or


w ord of the array of data pointed at by ES:DI w ith the
contents of the AL or AX. And depending on w hich prefix
REPE or REPNE is used, a decision is made for equality or
inequality.

5/11/2023 30
String Operations
 Example: (CM PS )

5/11/2023 31
String Operations
 Example: (SCANS)

5/11/2023 32
Table Operations
 XLAT instructions & Look-up tables:
 In some computer application, w e need a table that holds
some important information or some values.
 To access the elements in the table using the XLAT
(translate) instruction.
 The table is commonly referred to a look-up table.

 To access the square value for number 5:

5/11/2023 33
Any Question?

5/11/2023 34

You might also like