Module 2
Module 2
Fourth Generation
During 1980s
Low power version of HMOS technology
(HCMOS)
Third Generation 32 bit processors
During 1978 Physical memory space 224 bytes = 16 Mb
HMOS technology ⇒ Faster speed, Higher Virtual memory space 240 bytes = 1 Tb
packing density Floating point hardware
16 bit processors ⇒ 40/ 48/ 64 pins Supports increased number of addressing
Easier to program modes
Dynamically relatable programs
Processor has multiply/ divide arithmetic Intel 80386
hardware
More powerful interrupt handling
capabilities Second Generation
Flexible I/O port addressing During 1973
NMOS technology ⇒ Faster speed, Higher
Intel 8086 (16 bit processor) density, Compatible with TTL
4 / 8/ 16 bit processors ⇒ 40 pins
First Generation Ability to address large memory spaces
Between 1971 – 1973 and I/O ports
PMOS technology, non compatible with TTL Greater number of levels of subroutine
4 bit processors ⇒ 16 pins nesting
8 and 16 bit processors ⇒ 40 pins Better interrupt handling capabilities
Due to limitations of pins, signals are 1
multiplexed Intel 8085 (8 bit processor)
General Microprocessor Functional blocks
Overview
First 16 - bit processor released by
INTEL in the year 1978
3
8086 Microprocessor
Common signals
Address/Data bus
https://www.geeksforgeeks.org/pin-diagram-8086-microprocessor/ 4
8086 Microprocessor
Common signals
MN/ MX
MINIMUM / MAXIMUM
READY
CLK
9
8086 Microprocessor
Minimum mode signals
It stands for Data Enable and is available at pin 26. It is used to enable Transreceiver 8286.
The transreceiver is a device used to separate data from the address/data bus.
ALE
It stands for address enable latch and is available at pin 25. A positive pulse is generated
each time the processor begins any operation. This signal indicates the availability of a valid
address on the address/data lines.
8086 Microprocessor
Minimum mode signals
12
8086 Microprocessor
Maximum mode signals
13
8086 Microprocessor
Maximum mode signals
15
Inside The 8088/8086…pipelining
• Pipelining
– Two ways to make CPU process information faster:
• Increase the working frequency – technology dependent
• Change the internal architecture of the CPU
Four 16-bit
segment
registers
Code Segment
(CS)
Data Segment
(DS)
Stack Segment
(SS)
Extra Segment
(ES)
Architecture
Segment Code Segment Register
Registers
• 16-bit
• CS contains the base or start of the current code segment; IP contains the
distance or offset from this address to the next instruction byte to be fetched.
• BIU computes the 20-bit physical address by logically shifting the contents of CS
4-bits to the left and then adding the 16-bit contents of IP.
• That is, all instructions of a program are relative to the contents of the CS
register multiplied by 16 and then offset is added provided by the IP.
33
8086 Microprocessor
Bus Interface Unit (BIU)
Architecture
Segment Data Segment Register
Registers
• 16-bit
• Points to the current data segment; operands for most instructions are fetched
from this segment.
• The 16-bit contents of the Source Index (SI) or Destination Index (DI) or a
16-bit displacement are used as offset for computing the 20-bit physical
address.
34
8086 Microprocessor
Bus Interface Unit (BIU)
Architecture
Segment Stack Segment Register
Registers
• 16-bit
• The 20-bit physical stack address is calculated from the Stack Segment (SS) and
the Stack Pointer (SP) for stack instructions such as PUSH and POP.
• In based addressing mode, the 20-bit physical stack address is calculated from
the Stack segment (SS) and the Base Pointer (BP).
35
8086 Microprocessor
Bus Interface Unit (BIU)
Architecture
Segment
Registers
Extra Segment Register
• 16-bit
• Points to the extra segment in which data (in excess of 64K pointed to by the
DS) is stored.
• String instructions use the ES and DI to determine the 20-bit physical address
for the destination.
36
8086 Microprocessor
Bus Interface Unit (BIU)
Architecture
Segment
Registers Instruction Pointer
• 16-bit
37
8086 Microprocessor
Bus Interface Unit (BIU)
Instruction queue
Architecture
38
8086 Microprocessor
Execution Unit (EU)
A decoder in the EU
control system
translates instructions.
and
Some of the 16 bit registers can be
Index registers (Source used as two 8 bit registers as :
Index, Destination Index)
each of 16-bits AX can be used as AH and AL
BX can be used as BH and BL
CX can be used as CH and CL 39
DX can be used as DH and DL
8086 Microprocessor
Execution Unit (EU)
Architecture
EU Accumulator Register (AX)
Registers
40
8086 Microprocessor
Execution Unit (EU)
Architecture
EU Base Register (BX)
Registers
• Consists of two 8-bit registers BL and BH, which can be
combined together and used as a 16-bit register BX.
41
8086 Microprocessor
Execution Unit (EU)
Architecture
EU Counter Register (CX)
Registers
• Consists of two 8-bit registers CL and CH, which can be
combined together and used as a 16-bit register CX.
Example:
42
8086 Microprocessor
Execution Unit (EU)
Architecture
EU
Registers
43
8086 Microprocessor
Execution Unit (EU)
Architecture
EU Stack Pointer (SP) and Base Pointer (BP)
Registers
• SP and BP are used to access data in the stack segment.
44
8086 Microprocessor
Execution Unit (EU)
Architecture
EU Source Index (SI) and Destination Index (DI)
Registers
• Used in indexed addressing.
45
8086 Microprocessor
Architecture Execution Unit (EU)
Auxiliary Carry Flag
Carry Flag
Flag Register This is set, if there is a carry from the
This flag is set, when there is
lowest nibble, i.e, bit three during
addition, or borrow for the lowest a carry out of MSB in case of
nibble, i.e, bit three, during addition or a borrow in case
subtraction. of subtraction.
This flag is set, when the This flag is set, if the result of This flag is set to 1, if the lower
result of any computation the computation or comparison byte of the result contains even
is negative performed by an instruction is number of 1’s ; for odd number
zero of 1’s set to zero.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
OF DF IF TF SF ZF AF PF CF
Tarp Flag
Over flow Flag If this flag is set, the processor
This flag is set, if an overflow occurs, i.e, if the result of a signed enters the single step execution
operation is large enough to accommodate in a destination
mode by generating internal
register. The result is of more than 7-bits in size in case of 8-bit
signed operation and more than 15-bits in size in case of 16-bit interrupts after the execution of
sign operations, then the overflow will be set. each instruction
1. Register Addressing
Group I : Addressing modes for register and
2. Immediate Addressing immediate data
3. Direct Addressing
5. Based Addressing
Group II : Addressing modes for memory data
6. Indexed Addressing
8. String Addressing
1. Register Addressing
Addressing Modes
The instruction will specify the name of the
immediate data
8. String Addressing
48
8086 Microprocessor Group I : Addressing modes for register and
immediate data
1. Register Addressing
Addressing Modes
In immediate addressing mode, an 8-bit or 16-bit
2. Immediate Addressing data is specified as part of the instruction
3. Direct Addressing
Example:
4. Register Indirect Addressing
MOV DL, 08H
5. Based Addressing
The 8-bit data (08H) given in the instruction is
6. Indexed Addressing moved to DL
8. String Addressing
MOV AX, 0A9FH
9. Direct I/O port Addressing
The 16-bit data (0A9FH) given in the instruction is
10. Indirect I/O port Addressing
moved to AX register
11. Relative Addressing
(AX) ← 0A9FH
12. Implied Addressing
49
8086 Microprocessor
Adder
50
8086 Microprocessor
• Supported combinations:
BX SI
+ disp
BP DI 52
8086 Microprocessor Group II : Addressing modes for memory data
12. Implied Addressing This addressing mode is called direct because the
displacement of the operand from the segment
base is specified directly in the instruction.
53
8086 Microprocessor Group II : Addressing modes for memory
(CL) ← (MA)
(CH) ← (MA +1)
54
8086 Microprocessor Group II : Addressing modes for memory
Addressing Modes
In Based Addressing, BX or BP is used to hold the
data
1. Register Addressing
base value for effective address and a signed 8-bit
2. Immediate Addressing or unsigned 16-bit displacement will be specified
in the instruction.
3. Direct Addressing
In case of 8-bit displacement, it is sign extended
4. Register Indirect Addressing to 16-bit before adding to the base value.
(AL) ← (MA)
55
(AH) ← (MA + 1)
8086 Microprocessor Group II : Addressing modes for memory
(CL) ← (MA)
(CH) ← (MA + 1)
56
8086 Microprocessor Group II : Addressing modes for memory
57
8086 Microprocessor Group II : Addressing modes for memory
1. Register Addressing
data.
2. Immediate Addressing
The effective address (EA) of source data is stored
3. Direct Addressing in SI register and the EA of destination is stored in
DI register.
4. Register Indirect Addressing
Segment register for calculating base address of
5. Based Addressing source data is DS and that of the destination data
is ES
6. Indexed Addressing
Addressing Modes
These addressing modes are used to access data
ports
1. Register Addressing
from standard I/O mapped devices or ports.
2. Immediate Addressing
In direct port addressing mode, an 8-bit port
3. Direct Addressing address is directly specified in the instruction.
1. Register Addressing
Addressing Modes
2. Immediate Addressing
3. Direct Addressing
5. Based Addressing
6. Indexed Addressing
Instructions using this mode have no operands.
The instruction itself will specify the data to be
7. Based Index Addressing
operated by the instruction.
8. String Addressing
Example: CLC
9. Direct I/O port Addressing
This clears the carry flag to zero.
10. Indirect I/O port Addressing
61
8086 Microprocessor
Instruction Set
8086 supports 6 types of instructions.
2. Arithmetic Instructions
3. Logical Instructions
https://www.tutorialspoint.com/assembly_programming/assembly_logical_instructions.ht
m
62
8086 Microprocessor
Instruction Set
1. Data Transfer Instructions
Generally involve two operands: Source operand and Destination operand of the
same size.
A 8-bit data can only be moved to 8-bit register/ memory and a 16-bit data can be
moved to 16-bit register/ memory.
63
8086 Microprocessor
Instruction Set
1. Data Transfer Instructions
64
8086 Microprocessor
Instruction Set
1. Data Transfer Instructions
IN AL, [DX] PORT addr = (DX) OUT [DX], AL PORT addr = (DX)
(AL) ← (PORT) (PORT) ← (AL)
IN AX, [DX] PORT addr = (DX) OUT [DX], AX PORT addr = (DX)
(AX) ← (PORT) (PORT) ← (AX)
66
8086 Microprocessor
Instruction Set
2. Arithmetic Instructions
Mnemonics: ADD, ADC, SUB, SBB, INC, DEC, MUL, DIV, CMP…
ADD A, data
67
8086 Microprocessor
Instruction Set
2. Arithmetic Instructions
Mnemonics: ADD, ADC, SUB, SBB, INC, DEC, MUL, DIV, CMP…
ADC A, data
68
8086 Microprocessor
Instruction Set
2. Arithmetic Instructions
Mnemonics: ADD, ADC, SUB, SBB, INC, DEC, MUL, DIV, CMP…
SUB A, data
69
8086 Microprocessor
Instruction Set
2. Arithmetic Instructions
Mnemonics: ADD, ADC, SUB, SBB, INC, DEC, MUL, DIV, CMP…
SBB A, data
70
8086 Microprocessor
Instruction Set
2. Arithmetic Instructions
Mnemonics: ADD, ADC, SUB, SBB, INC, DEC, MUL, DIV, CMP…
71
8086 Microprocessor
Instruction Set
2. Arithmetic Instructions
Mnemonics: ADD, ADC, SUB, SBB, INC, DEC, MUL, DIV, CMP…
72
8086 Microprocessor
Instruction Set
2. Arithmetic Instructions
Mnemonics: ADD, ADC, SUB, SBB, INC, DEC, MUL, DIV, CMP…
73
8086 Microprocessor
Instruction Set
2. Arithmetic Instructions
Mnemonics: ADD, ADC, SUB, SBB, INC, DEC, MUL, DIV, CMP…
74
8086 Microprocessor
Instruction Set
2. Arithmetic Instructions
Mnemonics: ADD, ADC, SUB, SBB, INC, DEC, MUL, DIV, CMP…
75
8086 Microprocessor
Instruction Set
2. Arithmetic Instructions
Mnemonics: ADD, ADC, SUB, SBB, INC, DEC, MUL, DIV, CMP…
CMP A, data
76
8086 Microprocessor
Instruction Set
3. Logical Instructions
Mnemonics: AND, OR, XOR, TEST, SHR, SHL, RCR, RCL … ROR, ROL
77
8086 Microprocessor
Instruction Set
3. Logical Instructions
Mnemonics: AND, OR, XOR, TEST, SHR, SHL, RCR, RCL … ROR, ROL
78
8086 Microprocessor
Instruction Set
3. Logical Instructions
Mnemonics: AND, OR, XOR, TEST, SHR, SHL, RCR, RCL … ROR, ROL
79
8086 Microprocessor
Instruction Set
3. Logical Instructions
Mnemonics: AND, OR, XOR, TEST, SHR, SHL, RCR, RCL … ROR, ROL
The TEST instruction
works same as the AND
operation, but unlike
AND instruction, it does
not change the first
operand. So, if we need
to check whether a
number in a register is
even or odd, we can also
do this using the TEST
instruction without
changing the original
number.
80
8086 Microprocessor
Instruction Set
3. Logical Instructions
Mnemonics: AND, OR, XOR, TEST, SHR, SHL, RCR, RCL … ROR, ROL
81
8086 Microprocessor
Instruction Set
3. Logical Instructions
Mnemonics: AND, OR, XOR, TEST, SHR, SHL, RCR, RCL … ROR, ROL
82
8086 Microprocessor
Instruction Set
3. Logical Instructions
Mnemonics: AND, OR, XOR, TEST, SHR, SHL, RCR, RCL … ROR, ROL
83
8086 Microprocessor
Instruction Set
3. Logical Instructions
Mnemonics: AND, OR, XOR, TEST, SHR, SHL, RCR, RCL … ROR, ROL
84
8086 Microprocessor
Instruction Set
4. String Manipulation Instructions
❑ 8086 instruction set includes instruction for string movement, comparison, scan, load and store.
❑ String instructions end with S or SB or SW. S represents string, SB string byte and SW string word.
❑ Offset or effective address of the source operand is stored in SI register and that of the destination
operand is stored in DI register.
85
8086 Microprocessor
Instruction Set
4. String Manipulation Instructions
Mnemonics: REP, MOVS, CMPS, SCAS, LODS, STOS
Note: Always ‘REPZ’ instruction can be used in association with the string related
operations.
86
8086 Microprocessor
Instruction Set
4. String Manipulation Instructions
Mnemonics: REP, MOVS, CMPS, SCAS, LODS, STOS
MOVS
(MA E) ← (MA)
(MA E ; MA E + 1) ← (MA; MA + 1)
87
8086 Microprocessor
Instruction Set
4. String Manipulation Instructions
Mnemonics: REP, MOVS, CMPS, SCAS, LODS, STOS
CMPS
88
8086 Microprocessor
Instruction Set
4. String Manipulation Instructions
Mnemonics: REP, MOVS, CMPS, SCAS, LODS, STOS
Scan (compare) a string byte or word with accumulator
SCAS
LODS
90
8086 Microprocessor
Instruction Set
4. String Manipulation Instructions
Mnemonics: REP, MOVS, CMPS, SCAS, LODS, STOS
STOS
91
8086 Microprocessor
Instruction Set
5. Processor Control Instructions
Mnemonics Explanation
STC Set CF ← 1
CLC Clear CF ← 0
NOP No operation
ESC opcode mem/ reg Used to pass instruction to a coprocessor which shares the
address and data bus with the 8086
LOCK Lock bus during next instruction
92
8086 Microprocessor
Instruction Set
6. Control Transfer Instructions
Mnemonics Explanation
CALL reg/ mem/ disp16 Call subroutine
93
8086 Microprocessor
Instruction Set
6. Control Transfer Instructions
• Checks flags
94
8086 Microprocessor
Instruction Set
6. Control Transfer Instructions
Note: Before these instructions comparison instruction is to be used for comparing two operands. 95
8086 Microprocessor
Instruction Set
6. Control Transfer Instructions
Mnemonics Explanation
JC disp8 Jump if CF = 1
JP disp8 Jump if PF = 1
JO disp8 Jump if OF = 1
JS disp8 Jump if SF = 1
96
Iteration Control Instructions
These instructions are used to execute the given instructions for number of times.
Following is the list of instructions under this group −
LOOP − Used to loop a group of instructions until the condition satisfies, i.e., CX = 0
Assemble Directives
• Instructions to the Assembler regarding the program being executed.
• Control the generation of machine codes and organization of the program; but no
machine codes are generated for assembler directives.
• Used to :
› specify the start and end of a program
› attach value to variables
› allocate storage locations to input/ output data
› define start and end of segments, procedures, macros etc..
98
8086 Microprocessor
DB
Assemble Directives
• Define Byte
ASSUME • Range : 00H – FFH for unsigned value; 00H – 7FH for
positive value and 80H – FFH for negative value
ORG
END • General form : variable DB value/ values
EVEN
EQU
PROC
FAR Example:
NEAR LIST DB 7FH, 42H, 35H
ENDP
Three consecutive memory locations are reserved for the variable LIST
SHORT and each data specified in the instruction are stored as initial value in
the reserved memory location
MACRO
ENDM 99
8086 Microprocessor
DB
Assemble Directives
• Define Word
PROC
FAR Example:
NEAR ALIST DW 6512H, 0F251H, 0CDE2H
ENDP
Six consecutive memory locations are reserved for the variable ALIST
SHORT and each 16-bit data specified in the instruction is stored in two
consecutive memory location.
MACRO
ENDM 100
8086 Microprocessor
DB
Assemble Directives
• SEGMENT : Used to indicate the beginning of a code/ data/
stack segment
DW
• ENDS : Used to indicate the end of a code/ data/ stack
SEGMENT segment
ENDS
• General form:
ASSUME
ORG
END Seg_nam SEGMENT
EVEN
…
EQU … Program code
… or
PROC … Data Defining Statements
…
FAR …
NEAR
ENDP Seg_nam ENDS
SHORT
DB
Assemble Directives
• Informs the assembler the name of the program/ data
segment that should be used for a specific segment.
DW
• General form:
SEGMENT
ENDS
ASSUME segreg : segnam, .. , segreg : segnam
ASSUME
ORG
User defined name of the
END Segment Register
segment
EVEN
EQU
PROC Example:
FAR
NEAR ASSUME CS: ACODE, DS:ADATA Tells the compiler that the instructions of the
ENDP program are stored in the segment ACODE and
data are stored in the segment ADATA
SHORT
MACRO
ENDM 102
8086 Microprocessor
Assemble Directives
• ORG (Origin) is used to assign the starting address (Effective address)
DB
for a program/ data segment
ORG
Examples:
END
EVEN ORG 1000H Informs the assembler that the statements following
EQU ORG 1000H should be stored in memory starting with
effective address 1000H
PROC
FAR
LOOP EQU 10FEH Value of variable LOOP is 10FEH
NEAR
ENDP
_SDATA SEGMENT In this data segment, effective address of memory
SHORT ORG 1200H location assigned to A will be 1200H and that of B will
A DB 4CH be 1202H and 1203H.
EVEN
MACRO B DW 1052H
ENDM _SDATA ENDS 103
LENGTH: LENGTH is an operator, which tells the assembler to determine the number of
elements in some named data item, such as a string or an array. When the assembler reads
the statement MOV CX, LENGTH STRING1, for example, will determine the number of
elements in STRING1 and load it into CX. If the string was declared as a string of bytes,
LENGTH will produce the number of bytes in the string. If the string was declared as a word
string, LENGTH will produce the number of words in the string.
LENGTH: Byte length of a label: This is used to refer to the length of a data array or a
string. Ex : MOV CX, LENGTH ARRAY
OFFSET: offset of a label: When the assembler comes across the OFFSET operator along
with a label, it first computing the 16-bit offset address of a particular label and replace
the string ‘OFFSET LABEL’ by the computed offset address. Ex : MOV SI, offset list
Assemble Directives
• PROC Indicates the beginning of a procedure
DB
• ENDP End of procedure
DW
• FAR Intersegment call
SEGMENT
ENDS • NEAR Intrasegment call
• General form
ASSUME
ORG
Proc_name PROC[NEAR/ FAR]
END
EVEN …
… Program statements of the procedure
EQU
…
Last statement of the procedure
PROC RET
ENDP
FAR Proc_name ENDP
NEAR
DB
Assemble Directives
Examples:
DW
SEGMENT ADD64 PROC NEAR The subroutine/ procedure named ADD64 is declared
ENDS as NEAR and so the assembler will code the CALL
… and RET instructions involved in this procedure as
… near call and return
ASSUME …
RET
ORG
ADD64 ENDP
END
EVEN
EQU CONVERT PROC FAR The subroutine/ procedure named CONVERT is
declared as FAR and so the assembler will code the
… CALL and RET instructions involved in this
PROC … procedure as far call and return
ENDP …
FAR
RET
NEAR CONVERT ENDP
SHORT
MACRO
ENDM 106
8086 Microprocessor
Assemble Directives
DB • Reserves one memory location for 8-bit signed displacement
in jump instructions
DW
Example:
SEGMENT
ENDS
ASSUME JMP SHORT AHEAD The directive will reserve one memory
location for 8-bit displacement named
ORG AHEAD
END
EVEN
EQU
PROC
ENDP
FAR
NEAR
SHORT
MACRO
ENDM 107
8086 Microprocessor
Assemble Directives
DB • MACRO Indicate the beginning of a macro
PROC
ENDP
FAR
NEAR User defined name of the macro
SHORT
MACRO
ENDM 108
Procedures and Macros:
http://www.snjb.org/polytechnic/up-images/downloads/chapter%206-MAPupFile_058d4fa990abaa.pdf.
Define procedure : A procedure is a group of instructions that usually performs one task. It
is a reusable section of a software program stored in memory once but can be used as often
as necessary. A procedure can be of two types. 1) Near Procedure 2) Far Procedure
There are two types of calls. 1)Near Call or Intra segment call. 2) Far call or Inter Segment call
Operation for Near Call : When 8086 executes a near CALL instruction, it decrements the
stack pointer by 2 and copies the IP register contents on to the stack. Then it copies address
of first instruction of called procedure.
Operation of FAR CALL: When 8086 executes a far call, it decrements the stack pointer by 2
and copies the contents of CS register to the stack. It the decrements the stack pointer by 2
again and copies the content of IP register to the stack. Finally it loads CS register with base
address of segment having procedure and IP with address of first instruction in procedure.
8086 INTERRUPTS
Sources of Interrupts in 8086:
Executes ISR
Offset = 02 x 4 = 08
= 00008H
256 Interrupts of 8086 are Divided into 3 Groups
1. Type 00 to Type 04 interrupts -
These are used for fixed operations and hence are
called dedicated interrupts
¬
Type – 2:- Non-Maskable Interrupt
This interrupt is used for executing ISR of NMI pin
(positive edge signal), NMI can’t be masked by S/W.
¬
Type – 3:- One-byte INT instruction interrupt
Used for providing break points in the program
¬
An example of an interrupt generated
due to overflow error in an 8086 system
ASSUME CS:CODE, DS:DATA, SS:STACK_SEG CALL SUBTRACTION
MOV AH, 4CH
DATA SEGMENT INT 21H
NUM1 DB 50H Procedure Example
NUM2 DB 20H ADDITION PROC NEAR
ADD_RES DB ?
program: MOV AL, NUM1
SUB_RES DB ? MOV BL, NUM2
DATA ENDS ADD AL, BL
MOV ADD_RES, AL
STACK_SEG SEGMENT RET
ADDITION ENDP
DW 40 DUP(0) ; stack of 40 words, all initialized to zero
TOS LABEL WORD SUBTRACTION PROC
STACK_SEG ENDS MOV AL, NUM1
MOV BL, NUM2
CODE SEGMENT SUB AL, BL
MOV SUB_RES, AL
START: MOV AX, DATA ; initialize data segment RET
MOV DS, AX SUBTRACTION ENDP
MOV AX, STACK_SEG ; initialize stack segment
MOV SS, AX CODE ENDS
MOV SP, OFFSET TOS ; initialize stack pointer to TOS END START
CALL ADDITION
ASSUME CS:CODE, DS:DATA
DATA SEGMENT
NUM1 DW 1000H
NUM2 DW 2000H
RES DW ?
DATA ENDS MACRO program
CODE SEGMENT Example
ADDITION MACRO NO1, NO2, RESULT
MOV AX, NO1
MOV BX, NO2
ADD AX, BX
MOV RESULT, AX
ENDM
CODE ENDS
END START