Professional Documents
Culture Documents
MICROPROCESSORS 3 MICROPROCESSORS 4
Interrupt classification Response of the CPU
2. Exceptions:
The CPU responds to an interrupt request or at an exception
They are synchronous with the interrupted program in a similar way:
• Save the PC (Program Counter) contents (address of the next
Exceptions produces software traps, or software interrupts instruction) and supplementary information about current state (flags,
Generated by sources internal to CPU, i.e. unusual events registers, etc.)
produced in running a program: • Load PC with the beginning address of an Interrupt Service Routine
memory address violation (ISR) and start to execute it
illegal control instruction in a user program • Finish ISR and (usually) return to the interrupted program, to the point
in the current task from which it left.
arithmetic conditions (e.g. overflow, division by zero)
• The CPU responds to an interrupt request by a transfer of control to
page fault exceptions
another program in a manner similar to a subroutine call.
MICROPROCESSORS 5 MICROPROCESSORS 6
MICROPROCESSORS 9 MICROPROCESSORS 10
MICROPROCESSORS 11 MICROPROCESSORS 12
A vectored interrupt scheme A vectored interrupt scheme with IDT
Address (hex): Main memory
000C
Jump to
address F000
0040
Start
Interrupt Interrupt IHR 2
Register Mask
Register
0 1 N-1 01C0
Start
IHR 0
MICROPROCESSORS
Interrupt Request Lines 13 MICROPROCESSORS 14
memory map. In the Z8000 and Z80, however, the position of the table ARTI:
Z 80
is relative to the contents of an internal register. ISR
• An 8-bit vector allows for 256 entries in the vector table. The 8086
predefines or reserves 32 of these and care must be taken to avoid
generating these vectors externally. For MC68000, Z8000 and Z80, the
full range is available for user definition.
MICROPROCESSORS 15 MICROPROCESSORS 16
PENTIUM Interrupt system
Timing
There are three categories of interrupts, which depend on the source:
• Software interrupts: initiated with an INT instruction. For example INT
10h issues the interrupt with the hex number 10h • The time that elapses before an interrupt request is serviced depends on
several factors. The following all can affect elapsed time:
• Hardware interrupts: NMI and INTR. In real mode, for vectored
interrupts Pointer = 4*Vector (vector=number of interrupt). If the interrupt is masked, an INTR request will not be recognized
• Exceptions: originates in the processor itself, running instructions - until interrupts are re-enabled.
corresponds to that of a software interrupt: faults, traps and abort. If a NMI interrupt is currently being serviced, an incoming NMI
⇒ Fault: a fault issues an exception prior to completing the instruction interrupt request will not be recognized until IRET instruction.
(segment not present, overflow, coprocessor error) Saving the Flags register and other registers requires time.
⇒ Trap: issues an exception after completing instruction execution, and Time must be allowed for saving and restoring a task state in
the instruction is not re-executed. (debugger breakpoints, single step) interrupt servicing routine.
⇒ Abort: serious failures after that the recovery of program execution is Instruction are usually non-interruptible.
not always possible. (hardware failures, invalid system tables, division
Priorities (exceptions, software interrupts, NMI, INTR).
by 0, invalid opcode, bound exception
MICROPROCESSORS 17 MICROPROCESSORS 18
R1 R2 RN
MICROPROCESSORS 19 MICROPROCESSORS 20
HARDWARE STACK HARDWARE STACK
(4 words depth, 8 bits/word) (4 words depth, 8 bits/word)
PUSH A a7 a6 a5 a4 a3 a2 a1 a0
TS TS
stack stack
BS BS
MICROPROCESSORS 21 MICROPROCESSORS 22
TS a7 a6 a5 a4 a3 a2 a1 a0 TS a7 a6 a5 a4 a3 a2 a1 a0
stack stack
BS BS
MICROPROCESSORS 23 MICROPROCESSORS 24
HARDWARE STACK HARDWARE STACK
(4 words depth, 8 bits/word) (4 words depth, 8 bits/word)
POP
TS a7
b a6
b a5
b a4
b a3
b a2
b a1
b a0
b TS b7 b6 b5 b4 b3 b2 b1 b0
a7 a6 a5 a4 a3 a2 a1 a0 a7 a6 a5 a4 a3 a2 a1 a0
stack stack
BS BS
MICROPROCESSORS 25 MICROPROCESSORS 26
TS b7
a b6
a b5
a b4
a b3
a b2
a b1
a b0
a TS a7 a6 a5 a4 a3 a2 a1 a0
a7 a6 a5 a4 a3 a2 a1 a0
stack stack
BS BS
MICROPROCESSORS 27 MICROPROCESSORS 28
HARDWARE STACK HARDWARE STACK
(4 words depth, 8 bits/word) (4 words depth, 8 bits/word)
PUSH D d7 d6 d5 d4 d3 d2 d1 d0
TS a
c7 a
c6 a
c5 a
c4 a
c3 a
c2 a
c1 a
c0 TS c7 c6 c5 c4 c3 c2 c1 c0
a7 a6 a5 a4 a3 a2 a1 a0 a7 a6 a5 a4 a3 a2 a1 a0
stack stack
BS BS
MICROPROCESSORS 29 MICROPROCESSORS 30
TS d
c7 d
c6 d
c5 d
c4 d
c3 d
c2 d
c1 d
c0 TS d7 d6 d5 d4 d3 d2 d1 d0
a
c7 a
c6 a
c5 a
c4 a
c3 a
c2 a
c1 a
c0 c7 c6 c5 c4 c3 c2 c1 c0
stack stack
a7 a6 a5 a4 a3 a2 a1 a0 a7 a6 a5 a4 a3 a2 a1 a0
BS BS
MICROPROCESSORS 31 MICROPROCESSORS 32
HARDWARE STACK HARDWARE STACK
(4 words depth, 8 bits/word) (4 words depth, 8 bits/word)
PUSH G g7 g6 g5 g4 g3 g2 g1 g0
TS d
e7 d
e6 d
e5 d
e4 d
e3 d
e2 d
e1 d
e0 TS e7 e6 e5 e4 e3 e2 e1 e0
d
c7 d
c6 d
c5 d
c4 d
c3 d
c2 d
c1 d
c0 d7 d6 d5 d4 d3 d2 d1 d0
stack stack
a
c7 a
c6 a
c5 a
c4 a
c3 a
c2 a
c1 a
c0 c7 c6 c5 c4 c3 c2 c1 c0
BS a7 a6 a5 a4 a3 a2 a1 a0 BS a7 a6 a5 a4 a3 a2 a1 a0
MICROPROCESSORS 33 MICROPROCESSORS 34
HARDWARE STACK
(4 words depth, 8 bits/word)
Software (implemented) stack.
• Administration of stack is made by a special addressing register called
Stack Pointer (SP). SP register always contains the address of the
Top of the Stack (ToS).
TS e7
g e6
g e5
g e4
g e3
g e2
g e1
g e0
g
• Intel convention: stack memory grow towards lower addresses in MM
d7
e d6
e d5
e d4
e d3
e d2
e d1
e d0
e
stack • Filling in a data in stack memory (PUSH operation) means
d
c7 d
c6 d
c5 d
c4 d
c3 d
c2 d
c1 d
c0 decrementing the content of SP and then storing the data at the address
pointed by SP
BS a
c7 a
c6 a
c5 a
c4 a
c3 a
c2 a
c1 a
c0
• Pull out data from stack memory (POP operation) means reading data
a7 a6 a5 a4 a3 a2 a1 a0 addressed by SP and then updating the content of SP.
• The transfer with stack memory can be done in two ways:
automatic transfer.
stack transfer (special) instruction.
MICROPROCESSORS 35 MICROPROCESSORS 36
Example subroutine calls Subroutine calls-stack contents
MP P1 P2 time MP P1 P2
IN b: PUSH R1
Main IN
•
PUSH R2
PUSH R3 <t2>→ c: IN
IN b: PUSH R1 address memory •
•
<t1>→ IN
IN
IN
IN PUSH R2 t0 t1 t2 t3 t4 • •
IN . • •
• PUSH R3 <t2>→ c: IN <t0>→ .
CALL b
•
CALL c
. •
• <t1>→ IN IN <t4>→
a: IN <t3>→ d: IN
•
IN
RET
• IN SP x-7: dL •
.
.
•
•
• • • POP R3
• POP R2
x-6: dH
• •
POP R1
IN . RET
<t0>→ . • . • R3 END
MICROPROCESSORS 37 MICROPROCESSORS 38
Example Example
PC= 1
call 6
MICROPROCESSORS 39 MICROPROCESSORS 40
Example Example
SP 11
SP 7 7 7
2 2 2 2 2
PC= 1 6 PC= 1 6 10
call 10 call 3
MICROPROCESSORS 41 MICROPROCESSORS 42
Example Example
SP 4 SP 4 4
11 11 11 11 11
7 7 7 7 7 7 7
2 2 2 2 2 2 2 2 2
PC= 1 6 10 3 PC= 1 6 10 3 13
call 13 return
MICROPROCESSORS 43 MICROPROCESSORS 44
Example Example
4 4 4 4
SP 11 11 11 11 11 11 11 11
7 7 7 7 7 SP 7 7 7 7 7 7
2 2 2 2 2 2 2 2 2 2 2 2 2
PC= 1 6 10 3 13 4 PC= 1 6 10 3 13 4 11
return return
MICROPROCESSORS 45 MICROPROCESSORS 46
Example Example
4 4 4 4
11 11 11 11 11 11 11 11
7 7 7 7 7 7 7 7 7 7 7 7
SP 2 2 2 2 2 2 2 2 SP 2 2 2 2 2 2 2 2
PC= 1 6 10 3 13 4 11 7 PC= 1 6 10 3 13 4 11 7 2
return halt
MICROPROCESSORS 47 MICROPROCESSORS 48
Why Register Windows ?
• The main idea behind the use of register windows is to minimize
memory accesses.
• Procedure call and return occurs quite often in high-level
programming languages
– When translated into machine language, a procedure call produces
a sequence of instructions that save register values, pass
Overlapped parameters needed for the procedure, and then calls a subroutine to
execute the body of the procedure
– After a procedure return, the program restores the old register
Register Windows values, passes results to the calling program, and returns from the
subroutine
• Saving and restoring registers and passing of parameters and
results involve time consuming operations
• In RISC, overlapped register windows are used to avoid the
need for saving and restoring register values
– each procedure is allocated its own bank of registers
MICROPROCESSORS 50
MICROPROCESSORS 51 MICROPROCESSORS 52
R15 Common
to D and A
The R63
R58
R63
R58
Common
to C and D
EXAMPLE:
• The system has a total of 74 registers concept of PROC D R57
Local to C
R73
The R63
R58
R57 • Two pointers:
concept of – CWP - current window pointer - identifies the current
register window
the R48
R46
– SWP - saved window pointer
R42
overlapped Current
R41
Window overlapp
– The save operation (the called procedure is “saving”)
allocates a new register set by decrementing the CWP
register Register
Window
R32 – The restore operation de-allocates a register set by
R31
decrementing the CWP
window R26
R25
R16
R15
R10
MICROPROCESSORS 55 MICROPROCESSORS 56
Circular Buffer of windows
SWP Window 1
Call
procedure
Local Local
Window 4 P4 P2 Window 2
Return
CWP=1
MICROPROCESSORS Window 3 57