Individual Assignment (2)
Individual Assignment (2)
JIMMA UNIVERSITY
AGARO CAMPUS
COMPUTER SCIENCE DEPARTMENT
1
MICROPROCESSOR AND ASSEMBLY LANGUAGE INDIVIDUAL ASSIGNMENT
1)Definition of Interrupts
What is an interrupt?
2)Types of Interrupts
Interrupts can be broadly classified into hardware interrupts and software
interrupts, each serving distinct roles in a microprocessor system.
1
MICROPROCESSOR AND ASSEMBLY LANGUAGE INDIVIDUAL ASSIGNMENT
I) Hardware interrupt
Examples:
Keyboard Input: Pressing a key generates an interrupt for the processor to read
the key code.
Printer: A printer might send an interrupt when it runs out of paper.
Timer Interrupt: A periodic timer interrupt can trigger task switching in an
operating system.
Significance:
Examples:
System Calls: The INT 80h instruction in Linux is used for system calls like
reading or writing data.
Exception Handling: Division by zero can generate a software interrupt for
error handling.
Debugging Tools: Breakpoints in debuggers use software interrupts to halt
program execution.
Significance:
2
MICROPROCESSOR AND ASSEMBLY LANGUAGE INDIVIDUAL ASSIGNMENT
3) Interrupt Instructions
Interrupt instructions in assembly language are used to handle events and exceptions
in a microprocessor system. Below are the functions of the INT, INTO, INT 3, and
IRET instructions, along with simple code examples for each.
Function:
The INTO instruction triggers an interrupt if the overflow flag (OF) is set, indicating
an arithmetic overflow.
MOV AL, 127 ; Load AL with the maximum positive value for a signed byte
MOV AL, 1 ; Cause overflow
3
MICROPROCESSOR AND ASSEMBLY LANGUAGE INDIVIDUAL ASSIGNMENT
Function:
The INT 3 instruction is a special single-byte opcode interrupt primarily used for
debugging. It triggers a breakpoints in the debugger.
Function:
The IRET instruction is used to return from an interrupt service routine (ISR). It
restores the flags, code segment (CS), and instruction pointer (IP) from the stack.
Org 100h
MOV AX, 0 ; Clear AX
MOV BX, 0 ; Clear BX
CALL misery ;call the interrupt service routine
MOV CX, AX ; Verify result after return
RET
myISR:
MOV AX, 1234h ;Load a value into AX
IRET ;Return from interrupt
Summary
Instruction Purpose Typical Use Case
4
MICROPROCESSOR AND ASSEMBLY LANGUAGE INDIVIDUAL ASSIGNMENT
Real Mode
Real mode is the basic operating mode of x86 processors, used at system startup
and in legacy systems. It provides direct access to memory and hardware with
minimal protection mechanisms.
Limitations:
Protected Mode
Protected mode is an advanced mode introduced with the Intel 80286 processor,
providing enhanced memory protection, multitasking, and support for virtual
memory.
Memory Protection:
5
MICROPROCESSOR AND ASSEMBLY LANGUAGE INDIVIDUAL ASSIGNMENT
Role and Function: The primary role of the IF bit is to control whether the processor
will respond to mask-able interrupts. Mistakable interrupts are those that can be
ignored or delayed by the processor depending on the state of the IF bit.
IF = 1 (Enabled): When the IF bit is set to 1, mask able interrupts are enabled.
The processor will recognize and process incoming hardware interrupts,
transferring control to the corresponding interrupt service routine (ISR).
IF = 0 (Disabled): When the IF bit is cleared to 0, mask able interrupts are
disabled. The processor will ignore mask able interrupts, even if they occur, until
the IF bit is set back to 1.
Interrupt Handling Enabled: If the IF bit is set (1), the processor will
acknowledge and handle external hardware interrupts. Upon receiving an
interrupt request, the current instruction execution completes, and the control
is transferred to the appropriate ISR.
Interrupt Handling Disabled: If the IF bit is cleared (0), the processor will not
acknowledge mask able interrupts. This is useful in critical code sections
where the processor must not be interrupted, ensuring data integrity and
synchronization.
6
MICROPROCESSOR AND ASSEMBLY LANGUAGE INDIVIDUAL ASSIGNMENT
The IF bit can be modified using assembly instructions like CLI (Clear Interrupt
Flag) to disable interrupts and STI (Set Interrupt Flag) to enable them.
The PUSHF and POPF instructions can also be used to save and restore the entire
flag register, including the IF bit.
The structure of the IVT depends on the processor architecture, but generally, it is
organized as follows:
Entries:
The table consists of multiple entries, each associated with a unique interrupt
number.
Each entry stores a pointer (or vector) to the ISR handling the respective
interrupt.
· In x86 architecture:
o Each entry is 4 bytes (2 bytes for segment and 2 bytes for offset).
o A total of 256 entries are available, allowing for 256 unique interrupts.
7
MICROPROCESSOR AND ASSEMBLY LANGUAGE INDIVIDUAL ASSIGNMENT
ARM and other architectures may have different sizes and layouts based on
the design.
Each entry in the IVT stores a memory address (pointer) pointing to the ISR.
The memory address typically includes:
o Segment Address: Identifies the memory segment where the ISR
resides.
o Offset Address: Specifies the exact location within that segment.
Interrupt Identification:
The processor receives the interrupt and identifies the interrupt number.
Lookup in IVT:
The processor transfers control to the ISR, executing the routine to handle
the interrupt event.
Here's an outline of the basic steps involved in interrupt processing, along with what
happens to the CPU state and registers when an interrupt is triggered:
8
MICROPROCESSOR AND ASSEMBLY LANGUAGE INDIVIDUAL ASSIGNMENT
• Program Counter (PC): The current value of the PC is saved so that execution can
resume correctly after handling the interrupt.
• Flags/Status Information: Any condition flags or status information that could affect
program execution are also saved and restored after the ISR execution.
9
MICROPROCESSOR AND ASSEMBLY LANGUAGE INDIVIDUAL ASSIGNMENT
Return to Normal Execution: After the ISR has finished, the CPU resumes
its previous tasks. Depending on the operating system, it may re-enable
interrupts and handle other pending interrupts.
Interrupt Controller:
Vectoring: Sends the correct interrupt vector to the CPU to identify the
appropriate ISR.
CPU:
Execution: Pauses its current tasks to execute the ISR for the interrupt.
10
MICROPROCESSOR AND ASSEMBLY LANGUAGE INDIVIDUAL ASSIGNMENT
9) Nested Interrupts
Nested interrupts occur when an interrupt is triggered while another interrupt is
already being processed.
This means that the CPU must handle multiple interrupts simultaneously, which
can affect system performance and complexity
This requires the CPU to pause the current interrupt service routine (ISR) and
handle the higher-priority interrupt before resuming the initial ISR.
11
MICROPROCESSOR AND ASSEMBLY LANGUAGE INDIVIDUAL ASSIGNMENT
.model small
.stack 100h
.data
key db 0
.code
main:
mov ds, ax
int 21h
mov ah, 00h ; Function 00h: Read key from keyboard buffer
mov [key], al
int 21h
12
MICROPROCESSOR AND ASSEMBLY LANGUAGE INDIVIDUAL ASSIGNMENT
int 21h
end main
Explanation:
.model small specifies a small memory model, which means the code and data fit
within one segment.
.stack 100h reserves 256 bytes for the stack.
The message "Press a key: " is stored in the .data section, and a variable key is
declared to store the key pressed by the user.
Program Initialization:
The program begins by setting up the data segment (mov ax, @data and mov ds,
ax).
It then displays the prompt message to the user by calling interrupt int 21h with
function 09h.
The program waits for the user to press a key by invoking int 16h, which is
the keyboard interrupt.
After reading the key, the program stores the value of the AL register in the key
variable and displays it back on the screen using int 21h with function 09h.
The program exits by calling interrupt int 21h with function 4Ch, which
terminates the program and returns control to the operating system.
13
MICROPROCESSOR AND ASSEMBLY LANGUAGE INDIVIDUAL ASSIGNMENT
References:
Stallings, W. (2015). Computer Organization and Architecture. Pearson.
Mazidi, M.A., & Mazidi, J.G. (2010). The 8086 Microprocessor: Programming
and Interfacing the PC. Pearson.
Tanenbaum, A. S. (2013). Structured Computer Organization. Pearson.
Irvine, K. (2003). Assembly Language for Intel-Based Computers. Pearson.
John L. Hennessy and David A. Patterson.Computer Architecture: A Quantitative
Approach
"Assembly Language for x86 Processors" by Kip R. Irvine:
14