Professional Documents
Culture Documents
Part Three
8086
MICROPROCESSOR
PROGRAMING &
INSTRUCTION SETS
– Examples:
MOV CX, 592FH
MOV CL, [357AH]
MOV AL, CL
MOV 10[BP], AX
MOV CS:10[BP], AX
POP destination
Examples :
LEA AX, [BX][DI] ; Load AX with offset BX+DI
– MOVS/MOVSB/MOVSW
– REP/REPE/REPZ/REPNE/REPNZ
– LODS/LODSB/LODSW
– STOS/STOSB/STOSW
MOVS/MOVSB/MOVSW
– These instructions copy a byte or word from a location in the data
segment to a location in the extra segment.
REP/REPE/REPZ/REPNE/REPNZ
– REP is a prefix which is written before one of the string instructions.
These instructions repeat until specified condition exists.
Prepared by : Amanuel G ECE DEPARTEMENT
13 String Data Transfer Instructions
Example:
CLD
MOV AX, 0000H
MOV DS, AX
MOV ES, AX
MOV SI, 2000H
MOV DI, 2400H
MOV CX, 04H
REP MOVSB
Subtracts the number in the source from the number in the destination.
If you want to subtract a byte from a word, you must copy the byte to a word
location and fill the upper byte of the word with zeroes before subtracting.
In this instruction all status flags are affected.
– IMUL-If the upper byte of a 16-bit result or the upper word of 32-bit result contains only
copies of the sign bit (all 0’s or all 1’s), then the CF and the OF flags will both be 0’s.
– While for unsigned multiplication upper byte of word are filled with 0’s
E.g.:
MOV AX,2345H
MOV BX, 1111H
MUL BX
MOV [5000], AX
MOV [5002], DX
To divide a byte by a byte, it is necessary to put the dividend byte in AL and fill AH with
all 0’s. to divide a word by a word, it is necessary to put the dividend word in AX and fill
DX with all 0’s.
All status flags are undefined after a DIV instruction.
Example:
DIV CL ; word in AX/byte in CL, quotient in AL, remainder in AH.
DIV CX ; double word in DX and AX/word in CX, quotient in AX,
remainder in DX
IDIV Instruction : IDIV source
Used to divide a signed double word/word by a signed word/byte.
Rest all is similar to DIV instruction.
Prepared by : Amanuel G ECE DEPARTEMENT
26 Logical instructions
2. OR Dest, src
– Dest=register/memory location
– src = register/memory/immediate data
– Result is stored in Dest
E.g.
MOV AX, 3F0FH
MOV BX,0008H
OR AX,BX ; AX =3F9FH
Prepared by : Amanuel G ECE DEPARTEMENT
28 Logical instructions
3. NOT Operand
– Operand=register/memory location
– The instruction inverts the content of operand
– Result is stored in Accumulator
E.g.
MOV AX, 0200H
NOT AX; AX =DFF0H
4. RCR
– Also known as rotate right through carry
– Each binary bit rotate towards right by one position through carry
flag
– LSB B0 is placed in the carry flag
– Carry flag is placed in the MSB (B15) position
4. RCR
B15 B0 CF
1 1 0 1 0 0 1 0 0 0 0 1 0 0 0 1 0
After Execution
0 1 1 0 1 0 0 1 0 0 0 0 1 0 0 0 1
5. RCL
– Also known as rotate left through carry
– Each binary bit rotate towards left by one position through carry
flag
– LSB B0 is placed on B1
– MSB (B15) is placed in the Carry flag position
5. RCL
CF B15 B0
0 1 1 0 1 0 0 1 0 0 0 0 1 0 0 0 1
After Execution
1 0 0 1 0 0 1 0 0 0 0 1 0 0 0 1 0
Examples:
SAR BL, 1
MOV CL, 04H
SAR DX, CL
Prepared by : Amanuel G ECE DEPARTEMENT
35 Logical instructions
Examples: CF DATA
ROL CX, 1
MOV CL, 03H
ROL BL, CL
Prepared by : Amanuel G ECE DEPARTEMENT
36 Logical instructions
The numbers from 0-9 are represented as 30H – 39H in ASCII code
Examples:
; AL = 0000 0100 unpacked BCD 4
; CL = 0000 0110 unpacked BCD 6
MUL CL ; AL * CL result in AX
; AX = 0000 0000 0001 1000 = 0018H
AAM ; AX = 0000 0010 0000 0100 = 0204 which is unpacked BCD for 24.
– To get the ASCII number of result OR with 3030H
Exercise: ASCII 7* ASCII 6 Adjust the result using AAM
45
Converts two unpacked BCD digits in AH and AL to the equivalent binary
number in AL.
This adjustment must be made before dividing the two unpacked BCD digits in
AX by an unpacked BCD byte.
After the division AL will contain the unpacked BCD quotient and AH will contain
the unpacked BCD remainder.
The PF, SF, and ZF flags are updated. The AF, CF and OF flags are undefined after
AAD instruction.
Example:
; AX = 0403 unpacked BCD for 43 decimal, CL = 07H
AAD ; Adjust to binary before division
; AX = 002BH = 2BH = 43 decimal
DIV CL ; Divide AX by unpacked BCD in CL
; AL = quotient = 06 unpacked BCD:AH = remainder = 01 unpacked BCD
Prepared by : Amanuel G ECE DEPARTEMENT
46 String instructions
STRING INSTRUCTIONS
– SI is used to hold the offset of a byte/word in the source string and DI is used to
hold the offset of a byte/word in the other string.
– The comparison is done by subtracting the byte/word pointed to by DI from the
byte/word pointed to by SI.
– All status flags are affected, but neither operand is affected.
MOV CX, 100
MOV SI, OFFSET F_STRING
MOV DI, OFFSET S_STRING
STD
REPE CMPSB
SCAS/SCASB/SCASW Instruction :
Compares a string byte with a byte in AL or a string word with word in AX.
It affects only the status flags.
The string to be scanned must be in the extra segment and DI must contain the
offset of the byte or word to be compared.
i. CALL Des
– This instruction is used to call a subroutine or function or procedure.
– The address of next instruction after CALL is saved onto stack.
ii. RET
– It returns the control from procedure to calling program.
– Every CALL instruction should have a RET.
iii. JMP Des
– This instruction is used for unconditional jump from one place to another
Examples:
CALL PRO ; PRO is the name of the procedure. The assembler
determines displacement
; of PRO from the instruction after the CALL and
codes this displacement in as
; part of the instruction.
Examples:
JMP NEXT ; fetch next instruction from address at label NEXT. It is direct
jump and it can be
; short, near, or far jump depending on where the label is
located.
JMP BX ; it is an indirect near jump.
JMP WORD PTR [BX] ; indirect near jump.
JMP DWORD PTR [SI] ; indirect far jump.
Jxx Des
– All the conditional jumps follow some conditional statements or
any instruction that affects the flag
– conditional jumps are always short jumps in 8086.
JAE
CLC Instruction :
Resets the carry flag to zero. It does not affect any other flag.
CMC Instruction :
Complements the carry flag. It does not affect any other flag.
STD/CLD Instruction :
Used to set /clear the direction flag to one. It does not affect any other flag.
Instruction :
STI /CLI Instruction :
Sets the interrupt flag to one. This enables INTR interrupt of the 8086. it does not affect any other
flag. Resets the interrupt flag to zero. Due to this 8086 will not respond to an interrupt signal on its
INTR input. It does not affect any other flag.
Prepared by : Amanuel G ECE DEPARTEMENT
59
Reading ASSIGNMENT
1. External Hardware Synchronization Instructions
– HLT
– WAIT
– ESC
– LOCK
– NOP
2. Interrupt Instructions