Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Example
write the program required to out put the word in BX to
I/O ports 8004H and 8005H.
Solution
MOV DX, 8004H ;point DX at the port address
MOV AX, BX ;data must be in AX
OUT DX, AX ;output the data
The LEA (Load Effective Address) instruction will
load pointer and index registers with the effective
address of the labels
LEA BX, MEMBDS
Will load register BX with effective address of
MEMBDS. We would not have to know this address.
E0 1003H
00 1002H
80 1001H
“MEMDWDS” 10 1000H
Loads BX and DS with the contents of the double
word pointed at by SI.
• Example
Determine the contents of register AL and the state of
the flags after the following instructions are executed.
MOV AL, 6DH
MOV BH, 40H
AND AL, BH
• Solution
write the register contents in binary:
01101101 (AL)
01000000 (BH)
01000000 =40H (AL)
the flags are affected as follows:
CF = 0 ;CF is reset by the AND instruction
PF = 0 ;40H has an odd number of logic 1’s
AF = x ;AF is undefined
ZF = 0 ;the result is not zero
SF = 0 ;bit is reset
OF = 0 ;OF is reset by the AND instruction
• The applications of AND
1. The destination operand can be forced low by
choosing those bits as 0 in the source operand.
2. To consider the source operand a mask for testing
selected bits of the destination operand.
In the above example all bits are masked except bit 6.
if this bit is 0, the result is zero, if it is 1, the result is
non zero.
the instruction sequence
AND AL, BH
JZ START
will transfer control to memory location START if bit 6
of register AL is a 0
using the AND instruction results in a “destructive”
bit test because the contents of the destination
operand is altered by the instruction.
Solution
IN AL,0A0H
MOV BL, AL
IN AL, 0B0H
MUL BL
MOV DX, 7080H
OUT DX, AX
• Division can be performed on the word in AX or the
double word in DX:AX. The divisor can be an 8-bit or
a 16-bit memory location or CPU register.
• Note that the remainder is returned in register AH or
DX when the result does not come out even.
• Example
write a program to divide the unsigned word input at
indirect I/O port 8000H by 500D. Determine the result
if the input data is 56,723.
• Solution
MOV DX, 8000H
MOV BX, 01F4H
IN AX, DX
DIV BX
The result is AX=int(56,723/500) = 113=71H
And DX=mod(56,723/500)=223=00DFH
• Note
All forms of the loop instruction repeat until CX=0,
this means that the loop will be repeated 65,536
times if CX=0 initially.
Push and pop instructions
• It uses stack area of the memory.
• Recall SS is a 64K-B memory segment whose base
address determined by SS register. Two CPU
registers SP, and BP normally points into this area.
• SS segment is LIFO type of memory.
• Data is pushed onto the stack by the PUSH source
instruction
• The POP destination instruction causes the data
currently on top of the stack to be popped into the
destination operand.
• Note the stack actually grows downward with each
successive PUSH instructions.
• Example
PUSH CX
PUSH BX
SP 1000H
CH 0FFFH
SP’ CL 0FFEH
BH 0FFDH
SP’’ BL 0FFCH
• Registers should be popped off the stack in the
reverse order in which they were pushed on.
• Before using the stack it is important that register SP
be initialized to a high memory location allowing
room for the stack to grow.
CSH
CSL
SP’ is the new value of
register SP
IPH
SP’
IPL
• If an INT 23H is executed,
003FFH Type32-255
the processor will multiply
open
23H by 4 (rotate left twice),
00080H
Types 5-31 resulting in the jump table
Reserved address 0008CH.
by Intel
00014H
• CS and IP will then be
Type-4 1 K-B loaded with the double
overflow word stored in 0008CH
00010H through 0008FH (CS in the
Type-3
break point higher order word, IP in the
0000CH
Type-2 lower order word)
00008H
NMI • When ISR has finished, the
Type-1 IRET instruction should be
Single-step
00004H executed to pop the flag
Type-0 4 byte
register from stack (in
00000H addition to CS and IP).
Processor control instruction
• Used to control the operation of the processor and set
or clear the status indicators.
• DF, IF, and TF are processor control bits
• The STD (set direction flag) and CLD (clear direction
flag) instructions are used to set or clear this flag.
• STI (set interrupt enable flag) and CLI (clear interrupt
enable flag) enable or disable mask-able interrupts on
the INTR input line. Clearing this bit blocks all
interrupts on INTR effectively masking this input.
• There is no instruction for setting or resetting TF
(trap flag), but the following sequence of instructions
can be used to set TF.
PUSHF
MOV BP, SP
OR BYTE PTR[BP+1], 01H
POPF
• The HALT instruction will stop the processor and
cause it to enter an idle loop. However, once halted it
can be restarted only via a hardware interrupt or
system reset