Documente Academic
Documente Profesional
Documente Cultură
Chapter Outline
Data Transfer Instruction
Basic Arithmetic Instruction
The INT Instruction
Registers
Information inside the microprocessor is stored in registers.
The registers are classified according to the functions they perform
In general there are fourteen 16-bit registers:
Data registers:
There are four general data registers.
They hold data for an operation.
Address registers:
They are divided into segment, pointer, and index registers.
They hold the address of an instruction or data.
Status register:
It is called the FLAGS register.
It keeps the current status of the processor.
3
Registers
Data Registers
AX
BX
CX
DX
CS
DS
SS
ES
SI
DI
SP
BP
IP
AH
AL
BH
BL
CH
CL
DH
DL
Segment Registers
FLAGS Register
10
11
MOV Instruction
The MOV (move) instruction is used to:
Transfer data between Registers.
Transfer data between registers and memory locations.
Move a number directly into a register or memory location.
Note: any register can be used except CS & IP
Syntax:
MOV destination, source
Example:
MOV AX, WORD1
MOV AX, BX
MOV AX, 'A'
Before
0006
AX
0008
WORD1
After
0008
AX
0008
WORD1
12
Source operand
General register
Segment register
Memory location
Constant
Destination Operand
General Segment Memory
register register location
yes
yes
yes
yes
no
yes
yes
yes
no
yes
no
yes
Constant
no
no
no
no
14
15
16
XCHG Instruction
The XCHG (exchange) operation is used to exchange the contents
of:
Two registers.
A register and a memory location.
Syntax:
XCHG destination, source
Example:
XCHG AH, BL
XCHG AX,WORD1
Before
1A
00
AH
AL
After
05
00
AH
AL
00
BH
00
BH
05
BL
1A
BL
17
Source Operand
General register
Memory location
Destination Operand
General Memory
register location
yes
yes
yes
no
18
LEA Instruction
LEA (Load Effective Address) puts a copy of the source offset
address into the destination.
Syntax:
LEA destination, source
Where destination is a general register and source is a memory
location
Example:
MSG DB 41H, 42H, 43H
LEA DX, MSG
puts the offset address of the variable MSG into DX.
Data Definition + Basic Instructions
19
17
20
Examples:
ADD WORD1, AX
SUB AX, DX
Before
01BC
AX
0523
WORD1
After
01BC
AX
06DF
WORD1
Before
0000
AX
0001
DX
After
FFFF
AX
0001
DX
21
Source Operand
General register
Memory location
Constant
Destination Operand
General Memory
register location
yes
yes
yes
no
yes
yes
22
DEC destination
Examples:
INC WORD1
DEC BYTE1
Before
0002
WORD1
After
0003
WORD1
Before
FFFE
BYTE1
After
FFFD
BYTE1
23
INT Instruction
To invoke a DOS or BIOS routine, the INT (interrupt) instruction is
used.
Format:
INT interrupt_number
where interrupt_number is a number that specifies a routine.
INT 21h
INT 21h may be used to invoke a large number of DOS functions.
A particular function is requested by placing a function number in
the AH register and invoking INT 21h.
Some of the functions are:
Function number
1
2
9
Routine
single-key input
single-character output
character string output
INT 21h
Function 1: Single-Key Input
Input: AH = 1
Output: AL = ASCII code if character key is pressed
= 0 if non-character key is pressed
To invoke the routine, the following instructions should be executed:
MOV AH,1 ; input key function
INT 21H
; ASCII code in AL
INT 21h
Function 2: Display a character or execute a control function
Input: AH = 2
DL = ASCII code of the character
Output AL = ASCII code of the character
To invoke the routine, the following instructions should be executed:
MOV AH, 2
; display character function
MOV DL, '?'
; character is '?' (or any other character)
INT 21H
; display character
INT 21h
Function 2 may be used to perform control functions.
If DL contains the ASCII code of a control character, INT 21h
causes the control function to be performed.
The principal control characters are :
ASCII code (Hex)
07H
08H
09H
0AH
0DH
Symbol
BEL
BS
HT
LF
CR
Function
beep (sounds a tone)
backspace
tab
line feed (new line)
carriage return (start of current line)
INT 21h
Function 9: Display a string
Input: AH = 9
DX = offset address of string.
The string must end with a '$' character
To invoke the routine, the following instructions should be executed:
MOV AX, @DATA
A program containing a data segment should
begins with these two instructions
MOV DS, AX
MOV AH, 9
LEA DX, MSG
INT 21H
INT 21h
Function 4CH: Returning control to DOS
Input: AH = 4CH
To invoke the routine, the following instructions should be executed:
MOV AH, 4CH
; DOS exit function
INT 21H
; exit to DOS