0% found this document useful (0 votes)
22 views

Lab Manual - Mid-Sem

Uploaded by

Mukund Rathi
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views

Lab Manual - Mid-Sem

Uploaded by

Mukund Rathi
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 20

4

1. INTRODUCTION TO 8086 MICROPRCESSOR


AIM
To familiarize with the register organization and instruction set of 8086

THEORY
Intel 8086 was the first 16-bit microprocessor introduced by Intel in 1978.

REGISTER ORGANIZATION OF 8086


All the registers of 8086 are 16-bit registers. The general purpose registers can be used as
either 8-bit registers or 16-bit registers.
The register set of 8086 can be categorized into 4 different groups. The register organization
of 8086 is shown in the figure.

GENERAL DATA REGISTERS:


The registers AX, BX, CX and DX are the general purpose 16-bit registers. AX is used as 16-
bit accumulator. The lower 8-bit is designated as AL and higher 8-bit is designated as AH.
AL can be used as an 8-bit accumulator for 8-bit operation.
All data register can be used as either 16 bit or 8 bit. BX is a 16 bit register, but BL indicates
the lower 8-bit of BX and BH indicates the higher 8-bit of BX.
The register CX is used default counter in case of string and loop instructions.
The register BX is used as offset storage for forming physical address in case of certain
addressing modes.
DX register is a general purpose register which may be used as an implicit operand or
destination in case of a few instructions.

IEC 213 MICROPROCESSORS AND MICROCONTROLLERS DR. DELLA THOMAS


LAB MANUAL
5

Segment Registers:
The 8086 architecture uses the concept of segmented memory. 8086 able to address to
address a memory capacity of 1 megabyte and it is byte organized. This 1 megabyte memory
is divided into 16 logical segments. Each segment contains 64 Kbytes of memory.
Code segment register (CS): is used from addressing memory location in the code segment of
the memory, where the executable program is stored.
Data segment register (DS): points to the data segment of the memory where the data is
stored.
Extra Segment Register (ES): also refers to a segment in the memory which is another data
segment in the memory.
Stack Segment Register (SS): is used for addressing stack segment of the memory. The stack
segment is that segment of memory which is used to store stack data.
While addressing any location in the memory bank, the physical address is calculated from
two parts:
- The first is segment address, the segment registers contain 16-bit segment base addresses,
related to different segment.
- The second part is the offset value in that segment.
The advantage of this scheme is that in place of maintaining a 20-bit register for a physical
address, the processor just maintains two 16-bit registers which is within the memory
capacity of the machine.

Pointers and Index Registers.


The pointers contain offset within the particular segments.
- The pointer register IP contains offset within the code segment.
- The pointer register BP contains offset within the data segment.
- He pointer register SP contains offset within the stack segment.
The index registers are used as general purpose registers as well as for offset storage in The
register SI is used to store the offset of source data in data segment.
The register DI is used to store the offset of destination in data or extra segment.
The index registers are particularly useful for string manipulation.

IEC 213 MICROPROCESSORS AND MICROCONTROLLERS DR. DELLA THOMAS


LAB MANUAL
6

Flag register

Flag Register of 8086


 Conditional Flags
 Carry Flag (CY).
 Auxiliary Flag (AC)
 Parity Flag (PF)
 Zero Flag (ZF)
 Sign Flag (SF)
Control Flags
 Trap Flag (TF)
 Interrupt Flag (IF)
 Direction Flag (DF)
8086 INSTRUCTION SET SUMMARY
 Data Transfer Instructions
MOV Move byte or word to register or memory
IN, OUT Input byte or word from port, output word to port
LEA Load effective address
LDS, LES Load pointer using data segment, extra segment
PUSH, POP Push word onto stack, pop word off stack
XCHG Exchange byte or word
XLAT Translate byte using look-up table
 Logical Instructions
NOT Logical NOT of byte or word (one's complement)
AND Logical AND of byte or word
OR Logical OR of byte or word
XOR Logical exclusive-OR of byte or word
TEST Test byte or word (AND without storing)

IEC 213 MICROPROCESSORS AND MICROCONTROLLERS DR. DELLA THOMAS


LAB MANUAL
7

 Shift and Rotate Instructions


SHL, SHR Logical shift left, right byte or word by 1 or CL
SAL, SAR Arithmetic shift left, right byte or word by 1 or CL
ROL, ROR Rotate left, right byte or word by 1 or CL
RCL, RCR Rotate left, right through carry byte or word by 1 or CL

 Arithmetic Instructions
ADD, SUB Add, subtract byte or word
ADC, SBB Add, subtract byte or word and carry (borrow)
INC, DEC Increment, decrement byte or word
NEG Negate byte or word (two's complement)
CMP Compare byte or word (subtract without storing)
MUL, DIV Multiply, divide byte or word (unsigned)
IMUL, IDIV Integer multiply, divide byte or word (signed)
CBW, CWD Convert byte to word, word to double word (useful before
multiply/divide)
AAA, AAS,
AAM, AAD ASCII adjust for addition, subtraction, multiplication, division (ASCII
codes 30-39)
DAA, DAS Decimal adjust for addition, subtraction (binary coded decimal
numbers)

 Transfer Instructions
JMP Unconditional jump (short 127/8, near 32K, far between segments)
Conditional jumps:
JA (JNBE) Jump if above (not below or equal) +127, -128 range only
JAE (JNB) Jump if above or equal (not below) +127, -128 range only
JB (JNAE) Jump if below (not above or equal) +127, -128 range only
JBE (JNA) Jump if below or equal (not above) +127, -128 range only
JE (JZ) Jump if equal (zero) +127, -128 range only
JG (JNLE) Jump if greater (not less or equal) +127, -128 range only
IEC 213 MICROPROCESSORS AND MICROCONTROLLERS DR. DELLA THOMAS
LAB MANUAL
8

JGE (JNL) Jump if greater or equal (not less) +127, -128 range only
JL (JNGE) Jump if less (not greater nor equal) +127, -128 range only
JLE (JNG) Jump if less or equal (not greater) +127, -128 range only
JC, JNC Jump if carry set, carry not set +127, -128 range only
JO, JNO Jump if overflow, no overflow +127, -128 range only
JS, JNS Jump if sign, no sign +127, -128 range only
JNP (JPO) Jump if no parity (parity odd) +127, -128 range only
JP (JPE) Jump if parity (parity even) +127, -128 range only
Loop control:
LOOP Loop unconditional, count in CX, short jump to target address
LOOPE (LOOPZ) Loop if equal (zero), count in CX, short jump to target address
LOOPNE (LOOPNZ) Loop if not equal (not zero), count in CX, short jump to target
address
JCXZ Jump if CX equals zero (used to skip code in loop)

 Subroutine and Interrupt Instructions


CALL, RET Call Return from procedure (inside or outside current segment)
IRET Return from interrupt

 String Instructions
MOVS Move byte or word string
MOVSB, MOVSW Move byte, word string
CMPS Compare byte or word string
SCAS Scan byte or word string (comparing to A or AX)
LODS, STOS Load, store byte or word string to AL or AX
Repeat instructions (placed in front of other string operations):
REP Repeat
REPE, REPZ Repeat while equal, zero
REPNE, REPNZ Repeat while not equal (zero)

IEC 213 MICROPROCESSORS AND MICROCONTROLLERS DR. DELLA THOMAS


LAB MANUAL
9

 Processor Control Instructions


Flag manipulation:
STC, CLC, CMC Set, clear, complement carry flag
STD, CLD Set, clear direction flag
STI, CLI Set, clear interrupt enable flag
LAHF, SAHF Load AH from flags, store AH into flags
PUSHF, POPF Push flags onto stack, pop flags off stack

Coprocessor, multiprocessor interface:


ESC Escape to external processor interface
LOCK Lock bus during next instruction

Inactive states:
NOP No operation
WAIT Wait for TEST pin activity
HLT Halt processor

IEC 213 MICROPROCESSORS AND MICROCONTROLLERS DR. DELLA THOMAS


LAB MANUAL
10

2. MULTIBYTE ADDITION

MOV SI,3000
MOV DI,4000
MOV BX,2000
MOV CL,04
MOV DL,00
MOV AL, [BX]
ADD AL,[SI]
MOV [DI],AL
INC BX
INC SI
INC DI
LOOP BACK
JNC LABEL
ADC DL,00
LABEL: MOV [DI],DL

IEC 213 MICROPROCESSORS AND MICROCONTROLLERS DR. DELLA THOMAS


LAB MANUAL
11

3. MULTIBYTE SUBTRACTION

MOV SI,3000
MOV DI,4000
MOV BX,2000
MOV CL,04
MOV DL,00
MOV AL, [BX]
SUB AL,[SI]
MOV [DI],AL
INC BX
INC SI
INC DI
LOOP BACK
JNC LABEL
ADC DL,00
LABEL: MOV [DI],DL

IEC 213 MICROPROCESSORS AND MICROCONTROLLERS DR. DELLA THOMAS


LAB MANUAL
12

4. 8 BIT MULTIPLICATION

MOV SI, 2000


MOV AL, [SI]
MOV BL,[SI]01
MUL BL
MOV [SI]02,AX
INT 03

5. 16 BIT MULTIPLICATION

MOV SI, 2000


MOV AX, [SI]
MOV BX,[SI]02
MUL BX
MOV [SI]04,AX
MOV [SI]06,DX
INT 03

IEC 213 MICROPROCESSORS AND MICROCONTROLLERS DR. DELLA THOMAS


LAB MANUAL
13

6. 8 BIT DIVISION

MOV SI,2000
MOV AX,[SI]
MOV BL,[SI]02
DIV BL
MOV [SI]03,AX
INT 03

7. 32 BIT DIVISION
MOV SI,2000H
MOV AX,[SI]
MOV DX,[SI]02
MOV BX,[SI]04
DIV BX
MOV [SI]06,AX

IEC 213 MICROPROCESSORS AND MICROCONTROLLERS DR. DELLA THOMAS


LAB MANUAL
14

8. COUNT THE NUMBER OF 1’S IN THE CONTENTS OF D REGISTER AND STORE


THE COUNT IN THE B REGISTER

MVI B, 00H
MVI C, 08H
MOV AL,DL
BACK: ROR AX,01
JNC SKIP
INC BL
SKIP: DEC CL
JNZ BACK
INT 03

IEC 213 MICROPROCESSORS AND MICROCONTROLLERS DR. DELLA THOMAS


LAB MANUAL
15

9. ADDITION OF TWO 4 DIGIT BCD NUMBERS

CLC
MOV SI,2000H
MOV BX,3000H
MOV DI,4000H
MOV CX,02
L1:MOV AL,SI
ADC AL,{BX}
DAA
INC BX
INC SI
INC DI
DEC CX
JNX L1
INT 03

IEC 213 MICROPROCESSORS AND MICROCONTROLLERS DR. DELLA THOMAS


LAB MANUAL
16

10. SERIES OF N BYTES OR WORDS ADDITION

MOV SI,3000H
MOV CL,05
MOV AL,00H
MOV BL,00H
BACK: MOV DL,SI
ADD AL,DL
JNC LABEL
INC BL
LABEL: INC SI
JMP BACK
MOV SI,AL
MOV [SI]01,BL
INT 03H

IEC 213 MICROPROCESSORS AND MICROCONTROLLERS DR. DELLA THOMAS


LAB MANUAL
21

15. SQUARE AND CUBE OF A GIVEN NUMBER

MOV BX,3000
MOV AX,[BX]
MUL AX
MOV CX,AX
MOV AX,[BX]
MUL CX
INT 03

IEC 213 MICROPROCESSORS AND MICROCONTROLLERS DR. DELLA THOMAS


LAB MANUAL
22

16. FIND LARGEST/SMALLEST ELEMENT IN ARRAY

MOV SI, 6000


MOV CX,[SI]
MOV AX,0000H
BACK:INC SI
INC SI
CMP AX,[SI]
JAE GO
MOV AX,[SI]
GO: LOOP BACK
MOV [7000],AX

MOV SI, 6000


MOV CX,[SI]
MOV AX,0000H
BACK:INC SI
INC SI
CMP AX,[SI]
JB GO
MOV AX,[SI]
GO: LOOP BACK
MOV [7000],AX

IEC 213 MICROPROCESSORS AND MICROCONTROLLERS DR. DELLA THOMAS


LAB MANUAL
28

18. STRING INSTRUCTIONS

MOVSB – Move string byte SI to DI


MOVSW – Move string word SI to DI
REP – Repeats operation bit count becomes zero
CMPSB – Compare string byte DI
CMPSW – Compare string word
SCASB – Scan string byte DI
SCASW – Scan string word DI
CLD – Clear Direction flag – Auto Increment address
STD – SET Direction flag – Auto Decrement address
LODSB – Load string byte SI
LODSW – Load string word SI
STOSB – Store string byte DI
STOSW – Store string byte DI

IEC 213 MICROPROCESSORS AND MICROCONTROLLERS DR. DELLA THOMAS


LAB MANUAL
29

19. STRING OPERATIONS


19.1 LENGTH OF THE STRING BYTE

CLD
MOV DI, 3000
MOV CX, 0000
MOV AL,0FF
AGAIN:SCASB
JNZ COUNT
MOV BX, 5000
MOV [BX],CX
JMP EXIT
COUNT: INC CX
JMP AGAIN
EXIT: INT 03

19.2 LENGTH OF THE STRING WORD

CLD
MOV DI, 3000
MOV CX, 0000
MOV AX,0FFFF
AGAIN:SCASW
JNZ COUNT
MOV BX, 5000
MOV [BX],CX
JMP EXIT
COUNT: INC CX
JMP AGAIN
EXIT: INT 03

IEC 213 MICROPROCESSORS AND MICROCONTROLLERS DR. DELLA THOMAS


LAB MANUAL
30

19.3 SCANNING A BYTE OF STRING

MOV DI,3000
MOV BX,8000
MOV CX,0005
MOV SI,2000
MOV AL,[SI]
CLD
L2:SCASB
JNE X
MOV DL,00
MOV [BX],DL
JMP Y
X: LOOP L2
MOV DL,FF
MOV [BX],DL
Y: INT 03

IEC 213 MICROPROCESSORS AND MICROCONTROLLERS DR. DELLA THOMAS


LAB MANUAL
31

19.4 STRING RELOCATION

CLD
MOV SI,4000
MOV DI,5000
MOV CL,05
REP
MOVSB
INT 03

IEC 213 MICROPROCESSORS AND MICROCONTROLLERS DR. DELLA THOMAS


LAB MANUAL
32

19.5 REVERSE OF GIVEN STRING

MOV SI,2000
MOV DI,3000
MOV CX,0005H
ADD SI,CX
SUB SI,0001
BACK: STD
LODSB
CLD
STOSB
LOOP BACK
INT 03H

IEC 213 MICROPROCESSORS AND MICROCONTROLLERS DR. DELLA THOMAS


LAB MANUAL

You might also like