by dr. sikder sunbeam islam · 2019. 10. 29. · i (interrupt): the interrupt flag controls the...

38
Microprocessor: 8086 By Dr. Sikder Sunbeam Islam Associate Professor Department of Electrical and Electronic Engineering International Islamic University Chittagong

Upload: others

Post on 08-Mar-2021

4 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: By Dr. Sikder Sunbeam Islam · 2019. 10. 29. · I (interrupt): The interrupt flag controls the operation of the INTR (interrupt request) input pin. If I=1, the interrupt pin is enabled

Microprocessor: 8086 By

Dr. Sikder Sunbeam Islam Associate Professor

Department of Electrical and Electronic Engineering

International Islamic University Chittagong

Page 2: By Dr. Sikder Sunbeam Islam · 2019. 10. 29. · I (interrupt): The interrupt flag controls the operation of the INTR (interrupt request) input pin. If I=1, the interrupt pin is enabled

Introduction:8086 Features

8086 is Intel‟s first 16 bit Microprocessor

HMOS technology based

Packaged in 40-pin DIP(Dual in line package)

5V Power Supply

Cloak Speed: 5 MHz (up to 8MHz)

Has 20-bit address bus, hence it can address

up to of memory. Use segmented

memory

External clock generator (such as Intel 8284)

chip is needed.

Page 3: By Dr. Sikder Sunbeam Islam · 2019. 10. 29. · I (interrupt): The interrupt flag controls the operation of the INTR (interrupt request) input pin. If I=1, the interrupt pin is enabled

Introduction:8086 Features

continues

Has 16 bit data bus

Can be configured as (i) uni-processor

and (ii) multi-processor system (Bus

controller 8288 chip needed).

6 Instructions can be prefetched from

program memory and queues them in

order to speed up instruction

execution.

Page 4: By Dr. Sikder Sunbeam Islam · 2019. 10. 29. · I (interrupt): The interrupt flag controls the operation of the INTR (interrupt request) input pin. If I=1, the interrupt pin is enabled

8086 Architecture

The 8086 CPU is internally divided into

two independent functional units:

Dividing the work between these two

units speeds up processing.

Page 5: By Dr. Sikder Sunbeam Islam · 2019. 10. 29. · I (interrupt): The interrupt flag controls the operation of the INTR (interrupt request) input pin. If I=1, the interrupt pin is enabled

8086 Architecture

Page 6: By Dr. Sikder Sunbeam Islam · 2019. 10. 29. · I (interrupt): The interrupt flag controls the operation of the INTR (interrupt request) input pin. If I=1, the interrupt pin is enabled

Execution Unit (EU)

The Execution Unit of the 8086 tells the BIU where to fetch instructions or data form, decodes instructions and executes instructions.

Page 7: By Dr. Sikder Sunbeam Islam · 2019. 10. 29. · I (interrupt): The interrupt flag controls the operation of the INTR (interrupt request) input pin. If I=1, the interrupt pin is enabled

EU Registers:

The EU has nine 16 bit

registers AX, BX, CX,

DX, SP, BP, SI, DI and

Flag Register.

The 16 bit general

registers AX, BX, CX,

DX can be considered as

8 bit registers (AH, AL;

BH, BL; CH, CL; DH,

DL)

Fig. EU 16 bit registers

Page 8: By Dr. Sikder Sunbeam Islam · 2019. 10. 29. · I (interrupt): The interrupt flag controls the operation of the INTR (interrupt request) input pin. If I=1, the interrupt pin is enabled

EU Registers:

AX Resister(Accumulator Register) :

It is called 16 bit accumulator while AL is the 8-bit accumulator.

The I/O instruction always uses AX or AL for inputting/ outputting 16 or 8 bit data to or from an I/O port.

Multiplication and division instruction also use the AX or AL.

BX Resister(Base Register) :

It is called base Register because it sometimes holds the offset address of a location in the memory system in all version of microprocessor .

Page 9: By Dr. Sikder Sunbeam Islam · 2019. 10. 29. · I (interrupt): The interrupt flag controls the operation of the INTR (interrupt request) input pin. If I=1, the interrupt pin is enabled

EU Registers:

CX Resister(Counter Register) :

It is known as “Counter Register” because some

instructions such as SHIFT, ROTATE and LOOP

use the content of CX or CL as a counter.

Example: The instruction LOOP START will

automatically decrement CX by 1 without

affecting the flags and will check if [CX]=0 to

stop the loop.

DX Resister(Data Register) :

This general purpose register holds a part of the

result from multiplication or part of the dividend

before a division and reminder after the division.

Page 10: By Dr. Sikder Sunbeam Islam · 2019. 10. 29. · I (interrupt): The interrupt flag controls the operation of the INTR (interrupt request) input pin. If I=1, the interrupt pin is enabled

EU Registers: Flag Register

A flag register is flip flop that indicates some

condition produced by the execution of an

instruction or controls certain operations of the EU.

A 16-bit flag register contains 9 active flags.

Some flag changes after many arithmetic and logic

operations.

Flag never changes for any data transfer or

program control instruction/operation.

Six of the nine flags are used to indicate some

condition produced by an instruction. Let us now

discuss these flags:

Page 11: By Dr. Sikder Sunbeam Islam · 2019. 10. 29. · I (interrupt): The interrupt flag controls the operation of the INTR (interrupt request) input pin. If I=1, the interrupt pin is enabled

EU Registers: Flag Register

Page 12: By Dr. Sikder Sunbeam Islam · 2019. 10. 29. · I (interrupt): The interrupt flag controls the operation of the INTR (interrupt request) input pin. If I=1, the interrupt pin is enabled

Flag Register: Conditional flags

C (Carry) flag: This flag is set if a carry after addition or

the borrow after subtraction that has been generated out

of the most significant bit position during the last

result calculation. The carry flag also indicates error

condition, as dictated by some programs and procedures.

P (parity): This flag is set if the result has even parity

(number of „1‟ bits) ; it is zero if odd parity results.

For example, if a number contains three binary one bits, it

has odd parity.

A(auxiliary carry): It is set if the carry (half carry) after

addition or the borrow after subtraction between bit

position 3 and 4 of the result. This flag is used by BCD

arithmetic instruction (like, DAA). Otherwise, the A is zero.

Page 13: By Dr. Sikder Sunbeam Islam · 2019. 10. 29. · I (interrupt): The interrupt flag controls the operation of the INTR (interrupt request) input pin. If I=1, the interrupt pin is enabled

Flag Register: Conditional flags

Z(Zero): This flag is set if the result of an

arithmetic or logic operation is zero. If Z=1, the

result is zero; if Z=0, the result is not zero.

S (Sign): This flag is set if most significant bit of

the result is one; otherwise it is zero.

O (Overflow): Overflows occur when signed

numbers are added or subtracted. An overflow

indicates that the result has exceeded the capacity of

the machine or destination location.

The 8086 has three control bits in the flag register

that can be set or cleared by the programmer:

Page 14: By Dr. Sikder Sunbeam Islam · 2019. 10. 29. · I (interrupt): The interrupt flag controls the operation of the INTR (interrupt request) input pin. If I=1, the interrupt pin is enabled

Flag Register: Control flags

D (direction): The direction flag selects either the

increment and decrement mode for the DI (direction index)

and SI (source index) registers during string instructions.

If D=1, the registers are automatically decremented; if

D=0; the register are automatically incremented.

The D flag is set with the STD (set direction) and clear

with CLD (clear direction) instructions.

I (interrupt): The interrupt flag controls the operation of

the INTR (interrupt request) input pin. If I=1, the

interrupt pin is enabled. If I=0, the interrupt pin is

disabled. The state of the I flag bit is controlled by the STI

(set I flag) and CLI (clear I flag) instruction.

T (trap): Setting Trap flag puts the 8086 in a single step

mode. In this mode 8086 generates an internal interrupt

after execution of each instruction.

Page 15: By Dr. Sikder Sunbeam Islam · 2019. 10. 29. · I (interrupt): The interrupt flag controls the operation of the INTR (interrupt request) input pin. If I=1, the interrupt pin is enabled

BUS Interface Unit (BIU)

Page 16: By Dr. Sikder Sunbeam Islam · 2019. 10. 29. · I (interrupt): The interrupt flag controls the operation of the INTR (interrupt request) input pin. If I=1, the interrupt pin is enabled

BIU: The Queue

The BIU‟s instruction queue is a First-in-First-out (FIFO) group

of registers in which up to 6 bytes of instruction code are pre-

fetched from the memory ahead of time.

When EU is ready for its next instruction it simply reads the

instruction byte from this queue.

If BIU is interrupted by EU while in process of fetching an

instruction, the BIU first complete fetching and then services the

EU.

This is much faster than sending out an address to the system

memory and waiting for memory to send back the next

instruction byte or bytes.

Fetching the next instruction while the current instruction

executes is called pipelining.

If an instruction such as “Jump” or “Call” is encountered, the BIU

will reset the queue and begin refilling after passing the new

instruction to EU.

Page 17: By Dr. Sikder Sunbeam Islam · 2019. 10. 29. · I (interrupt): The interrupt flag controls the operation of the INTR (interrupt request) input pin. If I=1, the interrupt pin is enabled

BIU: Segment Registers

All segment registers are of 16-bits.

Code Segment (CS) register contains the base or start of the

current code segment and Instruction pointer (IP) register

contains the distance or offset from this address to the next

instruction byte to be fetched. Immediate data are considered as

part of code segment. Thus 20-bit physical address (PA) of

instruction is calculated from CS and IP (CS×10+ IP=PA).

The Stack segment (SS) register points to the current stack. It

is used to hold the 16 bits starting address for the program stack.

Stack is reserve area in the memory. Stack pointer (SP)

register is used as an offset from the current SS during

execution of an instruction. Thus 20-bit physical address of

current available stack is calculated from SS and SP (SS×10+

SP=PA).

The memory location where a word was most recently stored is

called the top of the stack.

Page 18: By Dr. Sikder Sunbeam Islam · 2019. 10. 29. · I (interrupt): The interrupt flag controls the operation of the INTR (interrupt request) input pin. If I=1, the interrupt pin is enabled

BIU: Segment Registers

Page 19: By Dr. Sikder Sunbeam Islam · 2019. 10. 29. · I (interrupt): The interrupt flag controls the operation of the INTR (interrupt request) input pin. If I=1, the interrupt pin is enabled

BIU: Segment Registers-Stack

PUSH operation is defined as writing to the top

or bottom of the stack.

POP operation means reading from top or bottom

of the stack.

When the stack pointer is accessed from the

bottom, the stack pointer is incremented after a

PUSH and decremented after POP operation

(reverse is done for top access).

When 8-bit accumulator is used, the stack pointer

(SP) is incremented and decremented by „1‟.

Whereas the SP is increment or decrement by „2‟

for16-bit registers.

Page 20: By Dr. Sikder Sunbeam Islam · 2019. 10. 29. · I (interrupt): The interrupt flag controls the operation of the INTR (interrupt request) input pin. If I=1, the interrupt pin is enabled

BIU: Seg.Reg.-Stack: PUSH

Page 21: By Dr. Sikder Sunbeam Islam · 2019. 10. 29. · I (interrupt): The interrupt flag controls the operation of the INTR (interrupt request) input pin. If I=1, the interrupt pin is enabled

BIU: Seg.Reg.-Stack: POP

Problem/Q: Suppose that an 8 bit microprocessor has a 16 bit stack pointer and uses

a 16 bit register in order to access the stack from the bottom. Assume that initially

the stack pointer and the 16 bit register contain 20C5 and 0120 respectively. After

a PUSH operation what are the contents of the stack pointer? What are the contents

of 20C6 and 20C7?

Page 22: By Dr. Sikder Sunbeam Islam · 2019. 10. 29. · I (interrupt): The interrupt flag controls the operation of the INTR (interrupt request) input pin. If I=1, the interrupt pin is enabled

Examples:

PUSHA; (Push all)—copies the content of the internal register

set ( following order AX,CX,DX, BX,SP,BP,SI and DI ), except

segment registers to stack.

PUSH ‘A’; pushes 0041 H (ASCII code of „A‟) to stack.

PUSHF; (Push flag)—copies the content of the Flag register to

stack.

PUSH BX, the first byte of data copied to stack (memory location

addressed by SP in the stack segment) .

POP BX; the first byte of data removed from stack (memory

location addressed by SP in the stack segment) into register BL.

POPA; (POP all), reverse of PUSHA.

POPF; reverse of PUSHF.

POPCS; not valid

POP 1000H—not valid.

BIU: Stack Seg: PUSH & POP instructions

Page 23: By Dr. Sikder Sunbeam Islam · 2019. 10. 29. · I (interrupt): The interrupt flag controls the operation of the INTR (interrupt request) input pin. If I=1, the interrupt pin is enabled

PUSH & POP

instructions

Examples:

PUSHA; (Push all)

PUSHF; (Push flag)

Page 24: By Dr. Sikder Sunbeam Islam · 2019. 10. 29. · I (interrupt): The interrupt flag controls the operation of the INTR (interrupt request) input pin. If I=1, the interrupt pin is enabled

Stack: Two Pointer Registers

Two pointer registers are used to access data in the

stack segment (SS) remains in EU:

Stack Pointer (SP) register is used as an offset (to

store data at stack memory) from the current SS

during execution of an Instruction. Its content is

automatically updated due to execution of a POP or

PUSH instruction.

Base Pointer (BP) register points to the memory

location for memory data transfer. BP contains an

offset address in the current SS. This offset is used in

based addressing mode.

BP may be considered as user stack pointer while

SP is the system stack pointer (as SP used by some

8086 instruction automatically like, CALL)

Page 25: By Dr. Sikder Sunbeam Islam · 2019. 10. 29. · I (interrupt): The interrupt flag controls the operation of the INTR (interrupt request) input pin. If I=1, the interrupt pin is enabled

BIU: Segment Registers

Extra Segment (ES) register and Data

Segment (DS) register are used to hold

the starting address of the two memory

segments that are used for data.

From DS-register operands for most

instructions are fetched.

ES-register points to the extra segment in

which extra data is stored. String

instruction uses ES and DS to find 20-

bit physical address for the destination.

Page 26: By Dr. Sikder Sunbeam Islam · 2019. 10. 29. · I (interrupt): The interrupt flag controls the operation of the INTR (interrupt request) input pin. If I=1, the interrupt pin is enabled

Two Index Registers

Two Index registers remains in EU: Source

Index (SI) and Destination Index(DI).

String Instruction uses SI and DI registers

together with DS and ES respectively in order to

distinguish between source and destination

addresses.

Page 27: By Dr. Sikder Sunbeam Islam · 2019. 10. 29. · I (interrupt): The interrupt flag controls the operation of the INTR (interrupt request) input pin. If I=1, the interrupt pin is enabled

Addressing Modes

There are various techniques to specify

address of data. These techniques are called

Addressing Modes.

The 8086 provides various addressing modes

to access instruction operands.

The 8086 has 12 addressing modes. These

modes can be classified into five groups:

Page 28: By Dr. Sikder Sunbeam Islam · 2019. 10. 29. · I (interrupt): The interrupt flag controls the operation of the INTR (interrupt request) input pin. If I=1, the interrupt pin is enabled

Addressing Modes: Register and

Immediate addressing mode

Register Addressing Mode: Register addressing transfers a

copy of a byte or word from the source register to destination

register. Example:

Mixing an 8-bit register with 16-bit, it is not allowed in

microprocessor

Code segment register (CS) is never used as destination.

Segment to segment MOV instruction is not allowed.

Page 29: By Dr. Sikder Sunbeam Islam · 2019. 10. 29. · I (interrupt): The interrupt flag controls the operation of the INTR (interrupt request) input pin. If I=1, the interrupt pin is enabled

Addressing Modes: Register and Immediate

addressing mode

Immediate Addressing Mode: Immediate addressing transfers

the source, an immediate byte or word data (i.e. constant

data), into the destination register.

Memory Addressing Mode: 8086 can not directly access to memory

operands. For accessing memory operands 8086 produces 20-bit

physical address using BIU.

Every memory addressing mode has a standard default segment

register. However, a segment override instruction can be placed before

most of the memory operand instructions whose default segment

register is to be overridden.

Page 30: By Dr. Sikder Sunbeam Islam · 2019. 10. 29. · I (interrupt): The interrupt flag controls the operation of the INTR (interrupt request) input pin. If I=1, the interrupt pin is enabled

Addressing Modes: Memory Addressing

Mode

Page 31: By Dr. Sikder Sunbeam Islam · 2019. 10. 29. · I (interrupt): The interrupt flag controls the operation of the INTR (interrupt request) input pin. If I=1, the interrupt pin is enabled

Addressing Modes: Memory Addressing

Mode

Register Indirect Addressing: Register addressing

transfers a byte or word between a register and memory

location addressed by an index or base register

(SI,DI,SP,BP).

Based Addressing: In this mode effective address is the

sum of displacement value and the contents of register BX

or BP.

Example: MOV AX, 4[BX]; moves the contents of 20-bit

address computed from segment register (DS or SS) and

offset [BX+4] into AX. Displacement can be 8 or 16 bit

signed.

Page 32: By Dr. Sikder Sunbeam Islam · 2019. 10. 29. · I (interrupt): The interrupt flag controls the operation of the INTR (interrupt request) input pin. If I=1, the interrupt pin is enabled
Page 33: By Dr. Sikder Sunbeam Islam · 2019. 10. 29. · I (interrupt): The interrupt flag controls the operation of the INTR (interrupt request) input pin. If I=1, the interrupt pin is enabled

Addressing Modes: Memory Addressing Mode

Indexed Addressing :Effective address is calculated from the

sum of displacement value and the contents of register SI or

DI.

Example: MOV CX, [BX+DI] ; Copies the word content of the

data segment memory location addressed by BX plus DI into

CX.

MOV [BP+DI], AH ; Copies AH into stack segment memory

location addressed by BP plus DI

Based-Indexed Addressing : Effective address is calculated

from the sum of base register, index register and displacement

value .

Example: MOV AX, 4[BX][DI] ; Moves the content s of 20-bit

address computed from the segment register (like, DS here)

and [BX]+[DI]+4 into AX.

Remember that BX, DI or SI addresses data segment and BP

addresses the stack segment.

Page 34: By Dr. Sikder Sunbeam Islam · 2019. 10. 29. · I (interrupt): The interrupt flag controls the operation of the INTR (interrupt request) input pin. If I=1, the interrupt pin is enabled

STRING ADDRESSING: This mode uses Index register. SI

is assumed to point to the first byte or word of the source

string and DI is assumed to point to the first byte or word of

the destination when string instruction is executed.

SI or DI is automatically incremented or decremented to point

to the next byte or word depending on DF (Direction flag)

The default segment register for Source is DS here.

EXAMPLE: MOVS WORD;

If [DF]=0, [DS]=3000H, [SI]=0020H, [ES]=5000H,

[DI]=0040H, [30020]=30H, [30021]=05H, [50040]=06H,

[50041]=20H.

After MOVS WORD, [50040]=30H, [50041]=05H,

[SI]=0021H, [DI]=0041H.

Addressing Modes: Memory Addressing Mode

Page 35: By Dr. Sikder Sunbeam Islam · 2019. 10. 29. · I (interrupt): The interrupt flag controls the operation of the INTR (interrupt request) input pin. If I=1, the interrupt pin is enabled

Two I/O port addressing is used : direct and

indirect port modes.

In either case 8 or 16 bit I/O transfer must take

via AL or AX register.

Example: Direct port mode: IN AL,02H; moves

the content of port 02 to AL register.

Indirect port mode: If [DX]=0020H, [Port

0020]=01H; [Port 0021]=03H; then after

IN AX,DX; the contents of register AX=0301H

Or, IN AL,DX; the contents of register AL=01H

Addressing Modes: Port Addressing

Page 36: By Dr. Sikder Sunbeam Islam · 2019. 10. 29. · I (interrupt): The interrupt flag controls the operation of the INTR (interrupt request) input pin. If I=1, the interrupt pin is enabled

Relative Addressing: Instruction in this mode

specify the operand as a signed 8-bit displacement

relative to PC.

Example: JNC START; (JNC-Jump if No Carry)

here if carry=0, the PC (program counter) is

loaded with current PC contents + the 8-bit signed

value START, otherwise next instruction will be

executed.

Implied Addressing: Instruction in this mode has

no operand.

Example: CLC; which clears the carry flag to zero.

Addressing Modes: Relative Addressing

Page 37: By Dr. Sikder Sunbeam Islam · 2019. 10. 29. · I (interrupt): The interrupt flag controls the operation of the INTR (interrupt request) input pin. If I=1, the interrupt pin is enabled

Exercise:

Q1. Spot the syntax errors in the following instructions:

Q2. Suppose that DS=1300H, SS=1400H, BP=1500H, BX=0100H,

SI=0100H and LIST=0008H. Determine the physical address accessed by

each of the following instructions:

(i) MOV DL, [BX+100] (ii) MOV CL,LIST[BX+SI] (iii) MOV

[BP+SI],AH

Page 38: By Dr. Sikder Sunbeam Islam · 2019. 10. 29. · I (interrupt): The interrupt flag controls the operation of the INTR (interrupt request) input pin. If I=1, the interrupt pin is enabled

References

Microprocessor and Interfacing Programming and Hardware;

Douglas V Hall, 2nd Edition.

Microprocessors and Microcomputer-Based System Design;

Mohammed Rafiquzzaman, revised edition.

Microprocessor & Interfacing Lecture Materials ;Mohammed Abdul

kader, IIUC.

The Intel Microprocessor; B.B. Brey, Seventh Edition.