L9 Merged
L9 Merged
2
Software Model of the 8086 Microprocessors
3
8086 Registers General Purpose Index
AH AL
BP
AX
SP
BH BL
BX
SI
CH CL
DI
CX
DH DL
DX Segment
CS
Flags DS
IP ES
4
General Purpose Registers
AX - the Accumulator
BX - the Base Register
CX - the Count Register
DX - the Data Register
• BX
– Base Register
– Also serves as an address register
6
General Purpose Registers
• 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
7
Pointer and Index Registers
Overflow Carry
Direction Parity
EU registers AX AH AL Accumulator
BX BH BL Base Register
CX CH CL Count Register
DX DH DL Data Register
SP Stack Pointer
BP Base Pointer
SI Source Index Register
DI Destination Index Register
FLAGS
10
The Stack
• The stack is used for temporary storage of information
such as data or addresses.
11
The Stack
12
What is an Instruction Set?
• The complete collection of instructions that are understood by a CPU
• Machine Code
• Binary
• Usually represented by programmer as assembly codes
Elements of an Instruction
• Operation code (Op code)
• Do this
• Source Operand reference
• To this
• Result Operand reference
• Put the answer here
• Next Instruction Reference
• When you have done that, do this...
Instruction Cycle State Diagram
Instruction Representation
• In machine code each instruction has a unique bit pattern
• For human consumption (well, programmers anyway) a symbolic
representation is used
• e.g. ADD, SUB, LOAD
• Operands can also be represented in this way
• ADD A,B
Simple Instruction Format
Instruction Types
• Data processing
• Data storage (main memory)
• Data movement (I/O)
• Program flow control
Number of Addresses (a)
• 3 addresses
• Operand 1, Operand 2, Result
• a = b + c;
• May be a forth - next instruction (usually implicit)
• Not common
• Needs very long words to hold everything
Number of Addresses (b)
• 2 addresses
• One address doubles as operand and result
• a=a+b
• Reduces length of instruction
• Requires some extra work
• Temporary storage to hold some results
Number of Addresses (c)
• 1 address
• Implicit second address
• Usually a register (accumulator)
• Common on early machines
Number of Addresses (d)
• 0 (zero) addresses
• All addresses implicit
• Uses a stack
• e.g. push a
• push b
• add
• pop c
• c=a+b
INSTRUCTION SET
• Data processing
• Data storage (main memory)
• Data movement (I/O)
• Program flow control
Number of Addresses (a)
• 3 addresses
– Operand 1, Operand 2, Result
– a = b + c;
– May be a forth - next instruction (usually implicit)
– Not common
– Needs very long words to hold everything
Number of Addresses (b)
• 2 addresses
– One address doubles as operand and result
–a = a + b
– Reduces length of instruction
– Requires some extra work
• Temporary storage to hold some results
Number of Addresses (c)
• 1 address
– Implicit second address
– Usually a register (accumulator)
– Common on early machines
8086 Microprocessor Instruction Set
2. Arithmetic Instructions
3. Logical Instructions
9
8086 Microprocessor
Instruction Set
10
8086 Microprocessor
Instruction Set
11
8086 Microprocessor
Instruction Set
13
8086 Microprocessor
Instruction Set
Condition of Flag
2. Arithmetic Instructions
ADD, ADC, SUB, SBB, CMP…
Affects CF, ZF, SF, OF, PF, AF.
INC, DEC
Affects ZF, SF, OF, PF, AF
MUL, IMUL, DIV, IDIV
Affects CF, OF
3. Logical Instructions
AND, OR, XOR, TEST, SHR, SHL, RCR, RCL
Affects CF, ZF, SF, OF, PF, AF
14
8086 Microprocessor Instruction Set
2. Arithmetic Instructions
Mnemonics: ADD, ADC, SUB, SBB, INC, DEC, MUL, DIV, CMP…
ADD A, data
15
8086 Microprocessor Instruction Set
2. Arithmetic Instructions
Mnemonics: ADD, ADC, SUB, SBB, INC, DEC, MUL, DIV, CMP…
ADC A, data
16
8086 Microprocessor Instruction Set
2. Arithmetic Instructions
Mnemonics: ADD, ADC, SUB, SBB, INC, DEC, MUL, DIV, CMP…
SUB A, data
17
8086 Microprocessor Instruction Set
2. Arithmetic Instructions
Mnemonics: ADD, ADC, SUB, SBB, INC, DEC, MUL, DIV, CMP…
SBB A, data
18
8086 Microprocessor Instruction Set
2. Arithmetic Instructions
Mnemonics: ADD, ADC, SUB, SBB, INC, DEC, MUL, DIV, CMP…
After DEC instruction we can use any JMP (Cond. Or Non-conditional) incase of loop
19
8086 Microprocessor Instruction Set
2. Arithmetic Instructions
Mnemonics: ADD, ADC, SUB, SBB, INC, DEC, MUL, DIV, CMP…
20
8086 Microprocessor Instruction Set
2. Arithmetic Instructions
Mnemonics: ADD, ADC, SUB, SBB, INC, DEC, MUL, DIV, CMP…
21
8086 Microprocessor Instruction Set
2. Arithmetic Instructions
Mnemonics: ADD, ADC, SUB, SBB, INC, DEC, MUL, DIV, CMP…
22
8086 Microprocessor Instruction Set
2. Arithmetic Instructions
Mnemonics: ADD, ADC, SUB, SBB, INC, DEC, MUL, DIV, CMP…
23
8086 Microprocessor Instruction Set
2. Arithmetic Instructions
Mnemonics: ADD, ADC, SUB, SBB, INC, DEC, MUL, DIV, CMP…
24
8086 Microprocessor Instruction Set
2. Arithmetic Instructions
Mnemonics: ADD, ADC, SUB, SBB, INC, DEC, MUL, DIV, CMP…
CMP A, data
25
SUM OF N CONSECUTIVE NUMBERS
INC BL BL = 02H
DEC CL CL = 02H
JNZ LOOP
MOV DI, 2002H
MOV [DI], AX
HLT
8086 Microprocessor Instruction Set
3. Logical Instructions
Mnemonics: AND, OR, XOR, TEST, SHR, SHL, RCR, RCL …
27
8086 Microprocessor
Instruction Set
3. Logical Instructions
Mnemonics: AND, OR, XOR, TEST, SHR, SHL, RCR, RCL …
28
8086 Microprocessor Instruction Set
3. Logical Instructions
Mnemonics: AND, OR, XOR, TEST, SHR, SHL, RCR, RCL …
29
8086 Microprocessor Instruction Set
3. Logical Instructions
Mnemonics: AND, OR, XOR, TEST, SHR, SHL, RCR, RCL …
30
8086 Microprocessor Instruction Set
3. Logical Instructions
Mnemonics: AND, OR, XOR, TEST, SHR, SHL, RCR, RCL …
31
8086 Microprocessor Instruction Set
3. Logical Instructions
Mnemonics: AND, OR, XOR, TEST, SHR, SHL, RCR, RCL …
32
8086 Microprocessor Instruction Set
3. Logical Instructions
Mnemonics: AND, OR, XOR, TEST, SHR, SHL, RCR, RCL …
33
8086 Microprocessor Instruction Set
3. Logical Instructions
Mnemonics: AND, OR, XOR, TEST, SHR, SHL, RCR, ROL …
34
8086 Microprocessor Instruction Set
35
8086 Microprocessor Instruction Set
MOVS
(MAE) (MA)
36
8086 Microprocessor
Instruction Set
In the example, the first form copies a single byte from the source string, at address DS:SI, to the destination string, at
address ES:DI, then increments (or decrements, if the Direction flag is set) both SI and DI.
The second form performs this operation and then decrements CX; if CX is not zero, the operation is repeated.
37
8086 Microprocessor Instruction Set
CMPS
38
8086 Microprocessor Instruction Set
LODS
39
8086 Microprocessor Instruction Set
STOS
40
8086 Microprocessor Instruction Set
CLC Clear CF 0
NOP No operation
41
8086 Microprocessor Instruction Set
Mnemonics Explanation
CALL reg/ mem/ disp16 Call subroutine
42
8086 Microprocessor Instruction Set
Checks flags
43
8086 Microprocessor Instruction Set
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
45
Branch Instruction
Nested Procedure Calls
Addressing modes
Dr. Umakanta Nanda
Dept. of ECE
VIT-AP
Addressing modes
Addressing mode is the way of locating the data or operands, the types of
operands used and the way they are accessed for executing an instruction.
Based on the flow of instructions, the instructions in 8086 can be categorized as
1. Sequential control flow instructions
2. Control transfer instructions
Sequential control flow are the instructions in which after execution, the control
is transferred to the next instruction appearing immediately after it in the
program.
Eg. Arithmetic instructions, logical, data transfer, and processor control
instructions.
Control transfer instructions transfer their control to some predefined address
after their execution. Eg. INT, CALL, RET, and JUMP instructions.
Addressing modes
Data of SI moved to AX IF
NO CX=00
?
Counter CX is assigned by 05
yes
YES
0000 is assigned to SI
Increment SI by 02 times
STOP
PROGRAM
Memory address level mnemonics
1000 MOV SI, 1200
MOV AX, [SI]
MOV CX, 05
GG12 INC SI
INC SI
CMP AX, [SI]
JE SS
JMP GG12
MOV SI, 0000
SS MOV [1400], SI
HLT
To separate odd and even numbers in a given
data array
Address Program Explanation
MOV CL, 06 Set counter in CL register
MOV SI, 1600 Set source index as 1600
MOV DI, 1500 Set Destination index as memory address 1500
Loop1: LODSB Load data from source memory
DEC CL Decrement the count
ROR AL, 01 Rotate AL once to right
JNB Loop1 If bit is zero Jump to Loop1
ROL AL,01 Rotate AL once to left
MOV [DI], AL Move result to Destination
INC DI Increment Destination index
CMP CL, 00H Compare CL to 00H
JNE Loop1 Jump if not equal to Loop1
HLT Stop the program
WAP to count the number of odd and even numbers in a given set of data array
Similarly write a program to separate –ve numbers from +ve numbers in a given set of data
CONVERSION OF BCD TO HEXADECIMAL
Write a program to sort a 8 bit data array in ascending order. The array consists of 5
numbers starting from location 3000H:4000H.
MOV AX,3000H
MOV DS,AX
MOV CH, 04H
L3: MOV CL,04H
MOV SI, 4000H
L2: MOV AL, [SI]
MOV AH, [SI+01H]
CMP AL, AH
JC L1
JZ L1
MOV [SI+1], AL
MOV [SI], AH
L1: INC SI
DEC CL
JNZ L2
DEC CH
JNZ L3
HLT
Program to check a number for bit wise palindrome. If
palindrome place FFH at 2500H or place 00H at 2500H
DATA SEGMENT
X DW 0FFFFH
MSG1 DB 10,13,'NUMBER IS PALINDROME$'
MSG2 DB 10,13,'NUMBER IS NOT PALINDROME$'
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START: MOV AX,DATA ;Load the Data to AX. MOV AX, [2300H]
MOV DS,AX ;Move the Data AX to DS.
MOV AX,X ;Move DW to AX.
MOV CL,10H ;Initialize the counter 10.
MOV CL,10H ;Initialize the counter 10. UP: ROR AX,1 ;Rotate right one time.
UP: ROR AX,1 ;Rotate right one time. RCL DX,1 ;Rotate left with carry one time.
RCL DX,1 ;Rotate left with carry one time. DEC CL
LOOP UP ;Loop the process.
CMP AX,DX ;Compare AX and DX. JNZ UP ;Loop the process.
JNZ DOWN ;If no zero go to DOWN label. CMP AX,DX ;Compare AX and DX.
LEA DX,MSG1 ;Declare as a PALINDROME. JNZ DOWN ;If no zero go to DOWN label.
MOV AH,09H
INT 21H
MOV [2500H], FFH ;Declare as a PALINDROME.
JMP EXIT ;Jump to EXIT label. JMP EXIT ;Jump to EXIT label.
DOWN: LEA DX,MSG2 ; Declare as not a PALINDROME DOWN: MOV [2500H], 00H ; Declare as not a PALINDROME
MOV AH,09H EXIT: HLT
INT 21H
EXIT:MOV AH,4CH
INT 21H
CODE ENDS
END START
WAP to reverse a string of 100 bytes using stack. Check whether the
string is palindrome or not. If it is palindrome display FFH on a display
unit whose address is 64H else display 00H.
MOV SI, 2300H MOV SI, 2300H
MOV DI, 2500H MOV DI, 2500H
MOV CL, 64H MOV CL, 64H
L1: MOV AL, [SI] CLD
PUSH AL REPZ CMPSB
JNZ L3
INC SI
MOV AL, FFH
DEC CL OUT 64H
JNZ L1 JMP Exit
MOV CL, 64H L3: MOV AL, 00H
L2: POP AL OUT 64H
MOV [DI], AL Exit: HLT
INC DI
DEC CL
JNZ L2
ALP to find the Sum of cubes of an array of size 10
by using 8086.
MOV SI,0200 H
MOV DI,0220H
MOV CL,0AH
MOV AX,0000 H
MOV [DI],AX
Up: MOV AL,[SI]
MOV BL,AL
MUL AL
MUL BL
ADD [DI],AX
INC SI
DEC CL
JNZ Up
HLT
Program to get the square root of a number
M0V AX, [0500H] move the data from offset 500 to register AX
MOV CX, 0000H move 0000 to register CX
MOV BX, FFFFH move FFFF to register BX
L1: ADD BX, 0002H add BX and 02
INC CX increment the content of CX by 1
SUB AX, BX subtract contents of AX with BX
JNZ L1 jump to address 040A if zero flag(ZF) is 0
MOV [600], CX store the contents of CX to offset 600
HLT end the program
Write a program to get Factorial of 10 numbers stored from the starting
location 4000H:1000H. The results should be stored in 4000H:2000H
MOV AX,4000H
MOV DS, AX
MOV SI,1000H
MOV DI, 2000H
Mov CL,0AH
MOV AL, 01H
Next:MOV BL,[SI]
LOOK:MUL BL
DEC BL
JNZ LOOK
MOV [DI], AL
INC SI
INC DI
LOOP NEXT
HLT
Write an ALP to convert binary number to gray code
Start
Move contents of AX to
1400 memory location
Stop
Program
MOV SI, 1200
SHR BX, 01
XOR AX, BX
MOV [1400], AX
HLT
Flowchart Start
No If equal
?
Yes
Move contents of AX to
Stop
1400 memory location
Program
Mnemonics
MOV SI, 1200
MOV AX, [ SI ]
MOV BX, [ SI ]
LOOP 1 SHR BX, 01
XOR AX, BX
CMP BX, 0000
JE LOOP 2
JMP LOOP 1
LOOP 2 MOV [ 1400 ], AX
HLT
Program to find Greatest common divisor (GCD) of
given numbers
MOV SI, 2300H ;Store Offset address 2300h in SI
MOV DI, 2400H ;Store offset address 2400h in DI
MOV AX, [SI] ;Move the first number to AX.
MOV BX, [SI+1] ;Move the second number to BX.
UP: CMP AX, BX ;Compare the two numbers.
JE EXIT ;If equal, go to EXIT label.
JB EXCG ;If first number is below than second, go to EXCG label.
UP1: MOV DX,0000H ;Initialize the DX.
DIV BX ;Divide the first number by second number.
CMP DX,0000H ;Compare remainder is zero or not.
JE EXIT ;If zero, jump to EXIT label.
MOV AX,DX ;If non-zero, move remainder to AX.
JMP UP ;Jump to UP label.
EXCG: XCHG AX,BX ;Exchange the remainder and quotient.
JMP UP1 ;Jump to UP1.
EXIT: MOV [DI], BX ;Store the result in DI.
HLT ; Stop
Program to find least common multiple (LCM) of a
given numbers
MOV SI, 2300H ;Store Offset address 2300h in SI
MOV DI, 2400H ;Store offset address 2400h in DI
MOV DX,0000H ;Initialize the DX
MOV AX,[SI] ;Move the first number to AX
MOV BX,[SI+2] ;Move the second number to AX
UP: PUSH AX ;Store the quotient/first number STACK
PUSH DX ;Store the remainder STACK
DIV BX ;Divide the first number by second number
CMP DX,0000H ;Compare the remainder.
JE EXIT ;If remainder is zero, go to EXIT label
POP DX ;If remainder is non-zero, ;Retrieve the remainder from stack
POP AX ;Retrieve the quotient from stack
ADD AX,[SI] ;Add first number with AX
JNC DOWN ;If no carry jump to DOWN label
INC DX ;Increment DX
DOWN: JMP UP ;Jump to Up label
EXIT: MOV [DI], AX ;If remainder is zero, store the value of LCM at destination
HLT ;Stop
Some important programs
• Program to count logical 1’s and 0’s in a given data
• Program for getting square of array of numbers
• Program to find LCM of a given numbers
• Program to find GCD of a given numbers
• Program to check a number is Bit wise palindrome or not
• Program to check a 16 bit number is Nibble wise palindrome or not
• Program to reverse a string
• Program to search for a character in a string
INTERRUPT
Bus arbitration for I/O devices
Data transfer techniques
The Purpose of Interrupts
I/O Organizations can be of 3 different types
1. Programmed I/O (Polling/Daisy chain)
2. Interrupt driven I/O
3. DMA
• Interrupts are useful when interfacing I/O devices with low data-transfer rates, like a keyboard or a mouse, in
which case polling the device wastes valuable processing time
• The peripheral interrupts the normal application execution, requesting to send or receive data.
• The processor jumps to a special program called Interrupt Service Routine to service the peripheral
• After the processor services the peripheral, the execution of the interrupted program continues.
3
Interrupts
• Interrupt Types
• Hardware Interrupts: External event
• Software Interrupts: Internal event (Software generated)
• Maskable and non-maskable interrupts
• Vectored and non vectored interrupts
• Interrupt priority
• Interrupt Vectors and Interrupt Handlers
• Interrupt Controllers
4
BASIC INTERRUPT TERMINOLOGY
• Interrupt pins: Set of pins used in hardware interrupts
• Interrupt Service Routine (ISR) or Interrupt handler: code used for
handling a specific interrupt
• Interrupt priority: In systems with more than one interrupt inputs, some
interrupts have a higher priority than other
• They are serviced first if multiple interrupts are triggered simultaneously
• Interrupt vector: Code loaded on the bus by the interrupting device that
contains the Address (segment and offset) of specific interrupt service
routine
• Interrupt Masking: Ignoring (disabling) an interrupt
• Non-Maskable Interrupt: Interrupt that cannot be ignored (power-down)
5
Interrupt processing flow Main program
Interrupt N
Req
Accept N
Interrupt
Get interrupt
vector
Jump to ISR
Save PC
Load PC
6
Hardware Interrupts – Interrupt pins and timing
• x86 Interrupt Pins
• INTR: Interrupt Request. Activated by a peripheral device to interrupt the processor.
• Level triggered. Activated with a logic 1.
• /INTA: Interrupt Acknowledge. Activated by the processor to inform the interrupting device the the
interrupt request (INTR) is accepted.
• Level triggered. Activated with a logic 0.
• NMI: Non-Maskable Interrupt. Used for major system faults such as power failures.
• Edge triggered. Activated with a positive edge (0 to 1) transition.
• Must remain at logic 1, until it is accepted by the processor.
• Before the 0 to 1 transition, NMI must be at logic 0 for at least 2 clock cycles.
• No need for interrupt acknowledgement.
INTR
INTA΄
D7-D0 Vector
7
Interrupt Vectors
• The processor uses the interrupt vector to determine the address of the ISR of the
interrupting device.
• In the 8088/8086 processor as well as in the 80386/80486/Pentium processors operating
in Real Mode (16-bit operation), the interrupt vector is a pointer to the Interrupt Vector
Table.
• The Interrupt Vector Table occupies the address range from 00000H to 003FFH (the
first 1024 bytes in the memory map).
• Each entry in the Interrupt Vector Table is 4 bytes long:
• The first two represent the offset address and the last two the segment address
of the ISR.
• The first 5 vectors are reserved by Intel to be used by the processor.
• The vectors 5 to 255 are free to be used by the user.
8
Interrupt Vector Table
9
Interrupt Vector - Example
•Draw a circuit diagram to show how a device with interrupt vector
4CH can be connected on an 8088 microprocessor system.
•Answer:
• The peripheral device activates the INTR line
• The processor responds by activating the INTA signal
• The NAND gate enables the 74LS244 octal buffer
• the number 4CH appears on the data bus
• The processor reads the data bus to get the interrupt vector
D7
Peripheral
Device
8088 System
D0
A0 Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0
E2 INTR
LS244
E1
I7 I6 I5 I4 I3 I2 I1 I0
A19 +5V
INTA
4C = 0 1 0 0 1 1 0 0
INTR
10
Interrupt Vector Table – Real Mode (16-bit) Example
•Using the Interrupt Vector Table shown below, determine the
address of the ISR of a device with interrupt vector 42H.
•Answer: Address in table = 4 X 42H = 108H
• (Multiply by 4 since each entry is 4 bytes)
• Offset Low = [108] = 2A, Offset High = [109] = 33
• Segment Low = [10A] = 3C, Segment High = [10B] = 4A
• Address = 4A3C:332A = 4A3C0 + 332A = 4D6EAH
0 1 2 3 4 5 6 7 8 9 A B C D E F
00000 3C 22 10 38 6F 13 2C 2A 33 22 21 67 EE F1 32 25
00010 11 3C 32 88 90 16 44 32 14 30 42 58 30 36 34 66
......... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
00100 4A 33 3C 4A AA 1A 1B A2 2A 33 3C 4A AA 1A 3E 77
00110 C1 58 4E C1 4F 11 66 F4 C5 58 4E 20 4F 11 F0 F4
......... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
00250 00 10 10 20 3F 26 33 3C 20 26 20 C1 3F 10 28 32
00260 20 4E 00 10 50 88 22 38 10 5A 38 10 4C 55 14 54
......... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
003E0 3A 10 45 2F 4E 33 6F 90 3A 44 37 43 3A 54 54 7F
11
003F0 22 3C 80 01 3C 4F 4E 88 22 3C 50 21 49 3F F4 65
Interrupt Vector Table – Real Mode (16-bit) Example
•Write a sequence of instructions that initialize vector 40H to point to the ISR “isr40”.
•Answer: Address in table = 4 X 40 = 100H
• Set ds to 0 since the Interrupt Vector Table begins at 00000H
• Get the offset address of the ISR using the Offset directive
• and store it in the addresses 100H and 101H
• Get the segment address of the ISR using the Segment directive
• and store it in the addresses 102H and 103H
push ax Save registers in the stack
push ds
mov ax,0
Set ds to 0 to point to the interrupt vector table
mov ds,ax
mov ax,offset isr40 Get the offset address of the ISR and store
mov [0100h],ax it in the address 0100h (4X40 = 100h)
mov ax,segment isr40 Get the segment address of the ISR
mov [0102h],ax and store it in the address 0102h
pop ds
Restore registers from the stack
pop ax
12
Interrupt Masking
• The processor can inhibit certain types of interrupts by use of a
special interrupt mask bit.
• This mask bit is part of the flags/condition code register, or a special
interrupt register.
• If this bit is clear, and an interrupt request occurs on the Interrupt
Request input, it is ignored.
• NMI cannot be masked
13
S/W Interrupt Processing
• Save state
• Disable interrupts for the duration of the ISR or allow it to be interrupted
too?
• Save program counter/Instruction Pointer
• Save flags
• Save register values?
• Jump to interrupt service routine
• Location obtained by interrupt vector
• Process interrupt
• Restore state
• Load PC/IP, flags, registers etc.
14
H/W Interrupt Processing
• External interface sends an interrupt signal, to the Interrupt Request (INTR) pin, (or an internal interrupt
occurs.)
• The CPU finishes the present instruction (for a hardware interrupt) and checks the INTR pin.
• If IF=0 the processor ignores the interrupt, else sends Interrupt Acknowledge (INTA) to hardware interface.
• The interrupt type N is sent to the Central Processor Unit (CPU) via the Data bus from the hardware
interface.
• The contents of the flag registers are pushed onto the stack.
• Both the interrupt (IF – FR bit 9) and (TF – FR bit 8) flags are cleared. This disables the INTR pin and the
trap or single-step feature.
• The contents of the code segment register (CS) are pushed onto the Stack.
• The contents of the instruction pointer (IP) are pushed onto the Stack.
• The interrupt vector contents are fetched, from (4 x N) and then placed into the IP and from (4 x N +2) into
the CS so that the next instruction executes at the interrupt service procedure addressed by the interrupt
vector.
• While returning from the interrupt-service routine by the Interrupt Return (IRET) instruction, the IP, CS and
Flag registers are popped from the Stack and return to their state prior to the interrupt.
15
The Intel x86 Interrupt Software Instructions
• All x86 processors provide the following instructions related to
interrupts:
• INT nn: Interrupt. Run the ISR pointed by vector nn.
• INT 0 is reserved for the Divide Error
• INT 1 is reserved for Single Step operation
• INT 2 is reserved for the NMI pin
• INT 3 is reserved for setting a Breakpoint
• INT 4 is reserved for Overflow (Same as the INTO (Interrupt on overflow)
instruction.
• CLI: Clear Interrupt Flag. IF is set to 0, thus interrupts are disabled.
• STI: Set Interrupt Flag. IF is set to 1, thus interrupts are enabled.
• IRET: Return from interrupt. This is the last instruction in the ISR (Real
Mode only). It pops from the stack the Flag register, the IP and the CS.
• After returning from an ISR the interrupts are enabled, since the initial value of
the flag register is poped from the stack.
16
Divide-By-Zero Interrupt-Type 0:
The 8086 will automatically do a type 0 interrupt if the result of a DIV operation or an IDIV operation is too large to fit in the destination
register. For a type 0 interrupt, the 8086 pushes the flag register on the stack, resets IF and TF and pushes the return addresses on the stack.
In other words, when in single step mode a system will stop after it executes each instruction and wait for further direction from user. The
8086 trap flag and type 1 interrupt response make it quite easy to implement a single step feature direction.
Non-maskable Interrupt-Type 2:
The 8086 will automatically do a type 2 interrupt response when it receives a low to high transition on its NMI pin. When it does a type 2
interrupt, the 8086 will push the flags on the stack, reset TF and IF, and push the CS value and the IP value for the next instruction on the
stack. It will then get the CS value for the start of the type 2 interrupt service procedure from address 0000AH and the IP value for the start
of the procedure from address 00008H. Needed to save the program data or processor status in case of power failure.
Breakpoint Interrupt-Type 3:
The type 3 interrupt is produced by execution of the INT3 instruction. The main use of the type 3 interrupt is to implement a breakpoint
function in a system. Whenever we insert a breakpoint, the system executes the instructions up to the breakpoint and then goes to the
breakpoint procedure.
Overflow Interrupt-Type4:
The 8086 overflow flag will be set if the signed result of an arithmetic operation on two signed numbers is too large to be represented in the
destination register or memory location.
Example: If we add the 8 bit signed number 01101100 and the 8 bit signed number 010111101, the result will be 10111101. This would be
the correct result if we were adding unsigned binary numbers, but it is not the correct signed result.
Intel 82C59A Interrupt Controller
• To allow the 8086 to handle a variety of devices and priority structures, it is
usually configured with an external interrupt arbiter, the 82C59A
• External devices are connected to the 82C59A, which in turn connects to
the 8086
• It accepts interrupt requests from attached modules, determines which
interrupt has the highest priority, and then signals the processor by raising
the INTR line
• The processor acknowledges via the INTA line.
• This prompts the 82C59A to place the appropriate vector information on
the data bus.
• The processor can then proceed to process the interrupt and to
communicate directly with the I/O module to read or write data
Programmable 82C59A
The 82C59A is programmable. The 8386 determines the priority
scheme to be used by setting a control word in the 82C59A.
The following interrupt modes are possible:
Fully nested: The interrupt requests are ordered in priority from 0
(IR0) through 7 (IR7)
Rotating: In some applications a number of interrupting devices are
of equal priority. In this mode a device, after being serviced, receives
the lowest priority in the group.
Special mask: This allows the processor to inhibit interrupts from
certain devices
Necessary materials to read for Interrupts
• Stallings book chapter: Input / Output (Chapter 7)
• Other materials will be provided in VTOP
Control Unit Operation
Prof. (Dr.) Umakanta Nanda
Department of ECE
VIT-AP
[email protected]
Micro-Operations
• A computer executes a program
• Fetch/execute cycle
• Each cycle has a number of steps called as micro-operations
• Each step does very little called atomic operation of CPU
Constituent Elements of
Program Execution
Fetch - 4 Registers
• Memory Address Register (MAR)
• Connected to address bus
• Specifies address for read or write op
• Memory Buffer Register (MBR)
• Connected to data bus
• Holds data to write or last data read
• Program Counter (PC)
• Holds address of next instruction to be fetched
• Instruction Register (IR)
• Holds last instruction fetched
Fetch Sequence
• Address of next instruction is in PC
• Address (MAR) is placed on address bus
• Control unit issues READ command
• Result (data from memory) appears on data
bus
• Data from data bus copied into MBR
• PC = PC+1 (in parallel with data fetch from
memory)
• Data (instruction) moved from MBR to IR
• MBR is now free for further data fetches
Fetch Sequence (symbolic)
• t1: MAR <- (PC)
• t2: MBR <- (memory)
PC <- (PC) +1
• t3: IR <- (MBR)
(tx = time unit/clock cycle)
or
• t1: MAR <- (PC)
• t2: MBR <- (memory)
• t3: PC <- (PC) +1
IR <- (MBR)
Rules for Clock Cycle Grouping
• Proper sequence must be followed
• MAR <- (PC) must precede MBR <- (memory)
• Conflicts must be avoided
• Must not read & write same register at same time
• MBR <- (memory) & IR <- (MBR) must not be in same cycle
• Also: PC <- (PC) +1 involves addition
• Use ALU
• May need additional micro-operations
Indirect Cycle
01
Functional Requirements
• Define basic elements of processor
• Describe micro-operations processor performs
• Determine functions control unit must perform
Basic Elements of Processor
• ALU
• Registers
• Internal data paths
• External data paths
• Control Unit
Types of Micro-operation
• Transfer data between registers
• Transfer data from register to external
• Transfer data from external to register
• Perform arithmetic or logical ops
Functions of Control Unit
• Sequencing
• Causing the CPU to step through a series of micro-operations
• Execution
• Causing the performance of each micro-op
• This is done using Control Signals
Control Signals-Input
• Clock
• One micro-instruction (or set of parallel micro-instructions) per clock cycle
• Instruction register
• Op-code for current instruction
• Determines which micro-instructions are performed
• Flags
• State of CPU
• Results of previous operations
• From control bus
• Interrupts
• Acknowledgements
Model of Control Unit
Control Signals - output
• Within CPU
• Cause data movement
• Activate specific functions
• Via control bus
• To memory
• To I/O modules
Example Control Signal Sequence - Fetch
• MAR <- (PC)
• Control unit activates signal to open gates between PC and MAR
• MBR <- (memory)
• Open gates between MAR and address bus
• Memory read control signal
• Open gates between data bus and MBR
Data Paths and Control Signals
Micro operations and control signals
ALU 7003H
7004H
7005H
IR FFFFH MBR FFFFH 7006H
7007H
7008H
Control Unit 7009H
Rd Wr
Implementation of
Control Unit
Prof. (Dr.) Umakanta Nanda
Department of ECE
VIT-AP
[email protected]
Control unit implementation
Implementation of Control unit is broadly of two types
• Hardwired implementation (RISC)
• Microprogrammed implementation (CISC)
Hardwired Implementation
Control unit inputs
• Flags and control bus
• Each bit means something
• Instruction register
• Op-code causes different control signals for each different instruction
• Unique logic for each op-code
• Decoder takes encoded input and produces single output
• n binary inputs and 2n outputs
• Clock
• Repetitive sequence of pulses
• Useful for measuring duration of micro-ops
• Must be long enough to allow signal propagation
• Different control signals at different times within instruction cycle
• Need a counter with different control signals for t1, t2 etc.
Control Unit with Decoded Inputs
C1
C2
C3
Is
x=0
Y N
?
C4 C5
C6
End
Sequence counter method
Micro-programmed Control unit
implementation
Prof. (Dr.) Umakanta Nanda
Department of ECE
VIT-AP
[email protected]
Wilkes’ Design for Micro programmed CU
Actual Microprogrammed control unit