Microprocessor and Microcontroller Lab
Dr. Shikha Marwaha
Department of Computer Science
and Engineering
School of Engineering
Shiv Nadar University Chennai
8086 Microprocessors
• 8086 has the ability to address up to 1 Mbyte of memory
• The 8086 is manufactured using high-performance metal-
oxide semiconductor (HMOS) technology
• The 8086 is housed in a 40-pin dual inline package and many
pins have multiple functions
8086 Microprocessors
• CMOS, Complementary Metal-Oxide-Semiconductor, is a major class of
integrated circuits used in chips such as microprocessors, microcontrollers, static
RAM, digital logic circuits, and analog circuits such as image sensors
8086 Microprocessors
• Two important characteristics of CMOS devices are high noise immunity and low
static power supply drain.
• Significant power is only drawn when its transistors are switching between on and
off states.
• CMOS devices do not produce as much heat as other forms of logic such as TTL.
• CMOS also allows a high density of logic functions on a chip
8086 Microprocessors Features
• It is a 16-bits microprocessor.
• It has 20 address lines so it can address 220 memory
locations (220 = 1,048,576 = 1 MB).
• It has 16- data lines .
• It has multiplexed address and data bus.
• It has 16 control lines.
• It requires only one, +5 V supply voltage.
• It is a 40 pin IC.
• It requires 5MHz clock frequency.
Intel 16-bit Registers
General Purpose Index
AH AL
BP
AX
SP
BH BL
BX
SI
CH CL
DI
CX
DH DL
DX Segment
CS
Status and Control SS
Flags DS
IP ES
Intel 16-bit Registers
• The
8086 has two parts, the Bus Interface Unit (BIU) and the
Execution Unit (EU).
• The BIU fetches instructions, reads and writes data, and computes the
20-bit address.
• The EU decodes and executes the instructions using the 16-bit ALU.
• The BIU contains the following registers:
IP - the Instruction Pointer
CS - the Code Segment Register
DS - the Data Segment Register
SS - the Stack Segment Register
ES - the Extra Segment Register
Intel 16-bit Registers
The EU contains the following 16-bit registers:
AX - the Accumulator
BX - the Base Register
CX - the Count Register
DX - the Data Register
SP - the Stack Pointer \ defaults to stack segment
BP - the Base Pointer /
SI - the Source Index Register
DI - the Destination Register
These are referred to as general-purpose registers, although, as seen by
their names, they often have a special-purpose use for some instructions.
Intel 16-bit Registers
The AX, BX, CX, and DX registers can be considers as two 8-bit registers, a
High byte and a Low byte. This allows byte operations and compatibility with
the previous generation of 8-bit processors, the 8080 and 8085.
The 8-bit registers are:
AX --> AH,AL
BX --> BH,BL
CX --> CH,CL
DX --> DH,DL
Intel 16-bit Registers
8086 internal registers 16 bits (2 bytes each)
AX, BX, CX and DX are two
bytes wide and each byte can
be accessed separately
These registers are used as
memory pointers.
Segment registers are used
as base address for a segment
in the 1 M byte of memory
8086 Microprocessors: Registers
• Registers
– Registers are in the CPU and are referred to by specific names
– Data registers
• Hold data for an operation to be performed
• There are 4 data registers (AX, BX, CX, DX)
– Address registers
• Hold the address of an instruction or data element
• Segment registers (CS, DS, ES, SS)
• Pointer registers (SP, BP, IP)
• Index registers (SI, DI)
– Status register
• Keeps the current status of the processor
– In total there are fourteen 16-bit registers in an 8086
Data Registers: AX, BX, CX, DX
• Instructions execute faster if the data is in a register
• AX, BX, CX, DX are the data registers
• Low and High bytes of the data registers can be accessed separately
– AH, BH, CH, DH are the high bytes
– AL, BL, CL, and DL are the low bytes
• Data Registers are general purpose registers but they also perform special functions
• AX
– Accumulator Register
– Preferred register to use in arithmetic, logic and data transfer instructions
because it generates the shortest Machine Language Code
– Must be used in multiplication and division operations
– Must also be used in I/O operations
Data Registers: AX, BX, CX, DX
• BX
– Base Register
– Also serves as an address register
– Used in array operations
– Used in Table Lookup operations (XLAT)
• CX
– Count register
– Used as a loop counter
– Used in shift and rotate operations
• DX
– Data register
– Used in multiplication and division
– Also used in I/O operations
Pointer and Index Registers
• Contain the offset addresses of memory locations
• Can also be used in arithmetic and other operations
• SP: Stack pointer
– Used with SS to access the stack segment
• BP: Base Pointer
– Primarily used to access data on the stack
– Can be used to access data in other segments
• SI: Source Index register
– is required for some string operations
– When string operations are performed, the SI register points to
memory locations in the data segment which is addressed by the DS
register. Thus, SI is associated with the DS in string operations.
Pointer and Index Registers
• DI: Destination Index register
• is also required for some string operations.
• When string operations are performed, the DI register points to memory
locations in the data segment which is addressed by the ES register. Thus, DI
is associated with the ES in string operations.
• The SI and the DI registers may also be used to access data stored in arrays
Segment Registers - CS, DS, SS and ES
• Are Address registers
• Store the memory addresses of instructions and data
• Memory Organization
– Each byte in memory has a 20 bit address starting with 0 to 220-1 or 1 meg of
addressable memory
– Addresses are expressed as 5 hex digits from 00000 - FFFFF
– Problem: But 20 bit addresses are TOO BIG to fit in 16 bit registers!
– Solution: Memory Segment
• Block of 64K (65,536) consecutive memory bytes
• A segment number is a 16 bit number
• Segment numbers range from 0000 to FFFF
• Within a segment, a particular memory location is specified with an offset
• An offset also ranges from 0000 to FFFF
16 - BIT ADDITION
MOV CX,0000H ALGORITHM:
➢ Start The Program.
MOV AX,[1200h]
➢ Initialize the register to store carry.
MOV BX, [1202h] ➢ Move the first Data Into the accumulator.
ADD AX,BX ➢ Move the second data into another register.
➢ Add or subtract the accumulator contents
JNC L1 with register contents.
INC CX ➢ If carry generated increment the CX
register.
MOV [1206h],CX ➢ Move the accumulator contents (result) any
L1:MOV [1204h], AX memory address
INT 3 Stop the execution.
PROGRAM TABLE:
Opcode
Address Label Mnemonic Operand Comments
FB SB TB
1000 B9 00 00 MOV CX,0000H Initialize counter CX
MOV AX,[1200] Get the first data in AX
1003 A1 00 12
register.
MOV BX, [1202] Get the second data in BX
1006 8B 1E 02
register.
ADD AX,BX Add the contents of both the
100A 03 C3
register AX & BX
100C 73 05 JNC JNC L1 Check for carry
INC CX If carry exists, increment the
100E 41
CX
100F 89 0E 06 MOV [1206],CX Store the carry
1013 A3 04 12 L1 MOV [1204], AX Store the sum
1014 F4 HLT Stop the program
OBSERVATION:
INPUTS [BEFORE EXECUTION] OUTPUTS [AFTER EXECUTION]
Memory location Memory location
Data Data
1200 02 1204 07
1201 05 1205 0C
1202 05 1206
1203 07 1207
CALCULATING THE SUM OF ‘N’ NUMBERS IN 8086
ALGORITHM: PROGRAM:
➢ Start The Program
➢ Initialize the counting value MOV CX.05H ; counter
➢ Get the first data in AX register MOV AX,0000H
➢ Get the first data in BX register MOV BX,0000H
➢ Move the input memory address 3000 to SI MOV SI,3000H
register MOV BL,[SI]
➢ Move the contents in SI to BL register ADD AX,BX
➢ Add the contents of both AX & BX register INC SI
➢ Increment the Source Index DEC CX
➢ Decrement the count for repetitions JNZ 2010
➢ Check if zero, if not zero, jump to loop MOV DI, 3050H
condition MOV [DI],AX
➢ Move the content of output memory
location to DI register
➢ Move the contents of AX register to DI
➢ Stop the program
CALCULATING THE SUM OF ‘N’ NUMBERS IN 8086
Address Opcode Label Mnemonic Operand Comments
2000 C7 C1 05 00 MOV CX,05H Initialize counter CX to
05H
2004 C7 C0 00 00 MOV AX,0000H Get the first data in AX
register.
2008 C7 C3 00 00 MOV BX,0000H Get the second data in BX
register.
200C C7 C6 00 30 MOV SI,3000H source address is 3000
2010 8A 1C MOV BL,[SI] move the content in SI to
BL
2012 01 D8 ADD AX,BX Add the contents of both
the register AX & BX
2014 46 INC SI Increment the SI
2015 49 DEC CX Decrement the CX
2016 75 F8 JNZ 2010 Jump until CX becomes
zero
2018 C7 C7 50 30 MOV DI,3050H move the contents in
3050 to DI
201C 89 05 MOV [DI],AX move the contents in AX
to DI
201E F4 HLT End of the process
Example
Memory Address Data (Hex) Decimal
3000H 02H 2
3001H 03H 3
3002H 01H 1
3003H 04H 4
3004H 05H 5
We want to find:
2 + 3 + 1 + 4 + 5 = 15
Step-by-Step Execution
Initialization
MOV CX, 05H → CX = 5 (loop will run 5 times)
MOV AX, 0000H → AX = 0 (sum)
MOV BX, 0000H → BX = 0
MOV SI, 3000H → SI points to first number
Loop Execution
1st Iteration
BL = [3000H] = 02H
BX = 0002H
AX = AX + BX = 0 + 2 = 2
SI = 3001H
CX = 4
Step-by-Step Execution
2nd Iteration 4th Iteration
BL = [3001H] = 03H BL = [3003H] = 04H
AX = 2 + 3 = 5 AX = 6 + 4 = 10
SI = 3002H SI = 3004H
CX = 3 CX = 1
3rd Iteration 5th Iteration
BL = [3002H] = 01H BL = [3004H] = 05H
AX = 5 + 1 = 6 AX = 10 + 5 = 15
SI = 3003H SI = 3005H
CX = 2 CX = 0 → Loop ends
Store the Result
MOV DI, 3050H
MOV [DI], AX
Address Value
3050H 000FH (15 decimal)
CALCULATING THE FACTORIAL OF A NUMBER
IN 8086
ALGORITHM: PROGRAM:
➢ Start The Program. MOV SI, 1000H
➢ Initialize the SI register with the starting MOV DI, 1010H
address of the first data MOV CL, [SI]
➢ Initialize the DI register with the output MOV AX,0001H
memory location MOV BX,AX
➢ Move the content of SI to CL register LOOP:INC BL
➢ Get the first data in AX register. MUL BL
➢ Move the contents of AX register to BX CMP BL,CL
➢ Increment the BL register JC LOOP
➢ Multiply the BL register with AX register. MOV [DI],AX
➢ Compare the content in CL with BL HLT
➢ Check if carry, jump to loop condition
➢ Move the contents of AX register to DI
➢ Stop the program.
PROGRAM TABLE
Address Opcode Label Mnemonic Operand Comments
3000 C7 C6 00 00 MOV SI, 1000H Source address is 1100
3004 C7 C7 10 10 MOV DI,1010H Move the 1010 value to
DI
3008 8A 0C - MOV CL, [SI] Move the content in SI
to CL
300A C7 C0 01 00 MOV AX,0001H Get the first data in AX
register.
300E 89 C3 - - MOV BX,AX Move the contents of
AX register to BX
3010 FE C3 - - INC BL Increment BL
3012 F6 E3 - - MUL BL Multiply BL
3014 38 CB - - CMP BL,CL Compare the content in
CL with BL
3016 72 F8 - - JC 3010H Jump to 3010 if carry
present
3018 89 05 - - MOV [DI],AX Move the contents in
AX to DI
301A F4 - - - HLT End of the process
OUTPUT:
INPUTS OUTPUTS [
[BEFORE AFTER
EXECUTION] EXECUTION]
Memory Data Memory Data
location location
1000 06 1010 D0
1011 02