Introduction To 8086 Programs

Download as pdf or txt
Download as pdf or txt
You are on page 1of 28

U19CS523- HARDWARE LABORATORY

8086 programs
1. Programs for 16 bit Arithmetic operations.
2. Programs for Sorting and Searching using MASM
3. Interfacing ADC and DAC.
4. Parallel Communication between two MP Kits using Mode 1 and Mode 2
of 8255.
5. Interfacing and Programming 8279, 8259, and 8253.
6. Interfacing and Programming of Stepper Motor and DC Motor Speed
control.
COVERED TOPICS
✔ 8086 BASICS

✔ ARITHMETIC OPERATIONS

✔ 8086 ADDRESSING MODES

✔ 8086 INSTRUCTION SETS

✔ ASSEMBLY LANGUAGE PROGRAMMING FOR ADDITION

✔ ASSEMBLY LANGUAGE PROGRAMMING FOR SUBRACTION

✔ VERIFY WITH EXAMPLE AND ASSEMBLER

✔ USE OF ALP
BASICS ABOUT 8086 PROCESSOR

• It was first 16-bit μP. (General purpose microprocessor)

• Its clock speed is 4.77 MHz, 8 MHz and 10 MHz,


depending on the version.

• Its data bus is 16-bit and address bus is 20-bit.

• It had 29,000 transistors.

• Could execute 2.5 million instructions per second.

• It could access 1 MB of memory.

• It had 22,000 instructions.

• 8086 employs parallel processing (prefetched bytes in a


FIFO is called instruction queue)
Data to be Store in Memory

Bit : A digit of the binary number or code is called a bit

Nipple : The 4 bit binary number

Byte : The 8 bit binary number

Word : The 16 bit binary number

Double Word : The 32 bit binary number

Multiple Word : The 64, 128.... Bit binary number


OPCODE

DECIMAL - 4 BIT- 9999 (MAXIMUM SIZE) = 10000 Information can be stored

HEXADECIMAL – 4BIT – FFFFh (65535 OR 2” 16)

Both are using same space but Hexadecimal giving more information
8086 ARCHITECTURE

Instruction Decoder
Translates instructions fetched
from memory into a series of
actions which EU Carried out.

Arithmetic Logic Unit (ALU)


EU has a 16 bit ALU which can
ADD, Subtract, AND, OR,
Increment, Decrement,
Complement, or Shift Binary
numbers.
General Purpose Registers

• EU has 8 general purpose registers.

• Can be individually used for storing 8 bit data.

• AL register is also called Accumulator

• Two registers can also be combined to form 16 bit registers.

• The valid registers pairs are – AX, BX, CX, DX

AX - Store 16 bit result of certain arithmetic & logic operations

BX - To hold the base value in base addressing mode to access memory data.

CX - To hold the count value in SHIFT, ROTATE, and LOOP instruction

DX - To hold data for Multiplication & Division


Contii..

SP - stack pointer - used to hold the offset address of the data stored at the top of stack segment

BP - Base Pointer - used to hold the offset address of the data to be read from or write into the stack segment

SI - Source Index register - used to hold the offset address of source data in data segment while executing
string instructions

DI - Destination Index register - used to hold the offset address of destination data in extra segment while
executing String instructions.

[segment - a portion of memory where data for a program is stored - the maximum size of a segment can be 64
bytes - minimum size of a segment can be even one byte - segment begins in memory at a memory address
which is divisible by 16]
FLAGS

CF (Carry Flag ) - This flag is set, when there is a carry out of MSB in case of addition or a borrow in case of
subtraction.

PF (Parity Flag) - This flag is set to 1,if the lower byte of the result contains even number of 1’s; for odd number of 1’s
set to zero.

AF ( Auxiliary Carry Flag ) - It is set if there is carry from low nipple to high nipple of the low order 8 bit of 16 bit
number

ZF ( Zero Flag ) - This flag set to one if the result is zero and ZF is clear to zero for non zero result

SF ( Sign Flag ) - This flag is set to one if the most significant bit of the result is one and SF is cleared to zero for non
negative result.

OF ( Overflow Flag ) - This flag is set One if there is an arithmetic overflow.


DF ( Direction Flag ) - This is used by string manipulation instructions. If this flag bit
is ‘0’, the string is processed beginning from the lowest address
to the highest address, i.e., auto incrementing mode. Other
wise, the string is processed from the highest address towards
the lowest address, i.e., auto decrementing mode.
IF ( Interrupt Flag ) - Causes the 8086 to recognize external mask interrupts; clearing IF
disables these interrupts
TF ( Trace Flag ) - If this flag is set, the processor enters the single step execution mode
by generating internal interrupts after the execution of each instruction.
Memory Segmentation
Addressing Mode
Register Addressing Mode

The instruction will specify the name of the register which holds the data to be operated by the instruction.

Example

MOV CL,DH DH CL (The 8 bit register DH is moved to another 8 Bit register CL. )

MOV BX,DX DX BX ( The 16 bit register DX is moved to another 16 Bit register BX)

Immediate Addressing Mode


An 8 bit or 16 bit data is specified as part of the instruction

Example

MOV DL,08H 08H DL (The 8 bit data (08H) given in the instruction is moved to DL register )

MOV AX,0A9FH 0A9FH AX (The 16 bit data (0A9FH) given in the instruction is moved to DL register )
Direct Addressing Mode

An unsigned 16bit displacement or signed 8 bit displacement will be specified in the instruction. The displacement is
the Effective Addressing (EA) or offset.

Eg: MOV DX, [08H]

Implied Addressing Mode

Eg: CLC Execution of this instruction will clear Carry Flag (CF)
8086 Instruction Set

Assembler:-it converts the instruction into sequence of binary bits, so that this bits can be read by the processor.

•Mnemonics:-these are the symbolic codes for either instructions or commands to perform a particular function.

E.g. MOV, ADD, SUB etc.

Types:

•Data Transfer Instructions

•Arithmetic Instructions

•Bit Manipulation Instructions

•String Instructions
Data Transfer Instruction

• There will be transfer of data from source to destination.

• Source can be register, memory location or immediate data.

• Destination can be register or memory operand.

• Both Source and Destination cannot be memory location or segment registers at the same time.
EXPERIMENT 1: Programs for 16 bit Arithmetic operations

ADDITION (WITHOUT CARRY)


Algorithm
PROGRAM:

MOV AX,[1000h] 1.Load the first data in AX register

MOV BX,[1002h] 2.Load the second data in BX register

MOV CL,00h
3.Clear CL register

ADD AX,BX
4.Add the two data and get the sum in AX
register
MOV [1004h],AX
5.Store the sum in memory
JNC jump
6.Check for Carry. If Carry flag is set than
INC CL go to next step, otherwise go to step 8.

jump: 7.Increment CL register

MOV [1006h],CL 8.Store the Carry in Memory

HLT 9.Stop
WITHOUT CARRY EXAMPLE
ADDITION (WITH CARRY)
SUBRACTION

• if carry flag value becomes 1 increment the CL value and that value store in particular memory address. Then take
2’s complement of the difference value then store into the output memory. (CL value becomes 1 its sign bit that
means output becomes negative)

MOV AX,[1000h] 1.Load the first data in AX register


MOV BX,[1002h] 2.Load the second data in BX register
MOV CL,00h
3.Clear CL register
SUB AX,BX
4.Subtract the two data and get the Difference AX register
JNC jump
INC CL 5.Check for Carry. If Carry flag is set than go to next step, otherwise go to step 8.
NOT AX 6.Increment CL register by one
ADD AX,0001h 7.Take 2’s Complement of the difference in AX register (Complement +1)
jump: 8.Store the Magnitude of difference in memory
MOV [1004h],AX
9.Store the Sign bit in Memory
MOV [1006h],CL
HLT 10.Stop
EXAMPLE
WITH BORROW EXAMPLE
Multiplication of Two 16 bit Data

• To perform multiplication in the 8086 processor, one of the data should be stored in AX register and another data
can be stored in the register/memory. After Multiplication, the product will be in AX and DX registers.
PROGRAM

MOV SI,1100H
1.Load the address of data in SI register
MOV AX,[SI]
2.Get the first data in AX register
MOV BX,[SI+2] 3.Get the Second data in BX register

MUL BX 4.Multiply the content of AX and BX. The product will be AX and DX

MOV [SI+4],AX 5.Save the product (AX and DX) in memory

6.Stop
MOV [SI+6],DX

HLT
DIVISION

MOV SI,1100H 1.Load the address of data in SI register


MOV AX,[SI]
2.Get the lower word of dividend in AX register
MOV DX,[SI+2]
3.Get the upper word of dividend in DX register
MOV BX,[SI+4]
4.Get the divisor in BX register
DIV BX
5.Perform division to get quotient in AX and remainder in DX
MOV [SI+6],AX

MOV [SI+8],DX 6.Save the quotient (AX) and the remainder (DX) in memory

HLT 7.Stop
EXAMPLE
APPLICATIONS

• Calculators
• Accounting system
• Games machine
• Instrumentation
• Traffic light Control
• Multi user, multi-function environments
• Military applications
• Communication systems
• Remote Controller
Thank You

You might also like