0% found this document useful (0 votes)
9 views7 pages

Lab 13 sol

The document is a laboratory manual for a course on Computer Organization and Assembly Language Programming at the National University of Computer and Emerging Sciences. It outlines objectives and tasks involving programmable interrupt controllers, timer interrupts, and keyboard behavior modifications, including code examples for frequency counting, custom message display, and chaining multiple interrupt handlers. The manual is intended for students to gain practical experience in handling interrupts and programming in assembly language.

Uploaded by

sana ejaz
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views7 pages

Lab 13 sol

The document is a laboratory manual for a course on Computer Organization and Assembly Language Programming at the National University of Computer and Emerging Sciences. It outlines objectives and tasks involving programmable interrupt controllers, timer interrupts, and keyboard behavior modifications, including code examples for frequency counting, custom message display, and chaining multiple interrupt handlers. The manual is intended for students to gain practical experience in handling interrupts and programming in assembly language.

Uploaded by

sana ejaz
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

National University of Computer and Emerging Sciences

Laboratory Manual

for
Computer Organization and Assembly Language Programming

Lab Instructor Sana Ejaz


Semester Fall 2024

Department of Computer Science

FAST-NU, Lahore, Pakistan

Page 1
OBJECTIVES:

 Learn to manipulate and handle Programmable Interrupt Controller (PIC) ports.


 Experiment with interrupt chaining and unhooking interrupts for custom handling.
 Explore the basics of the Programmable Interval Timer (PIT) and its integration with
interrupts.
 Gain insight into terminating and staying resident (TSR) programs and their applications.

Task 1: Frequency Counter Using Timer Interrupt


Measure the frequency of an external event using the timer interrupt.
 Hook INT 08h and set up a counter for timer ticks.
 Monitor an external input (e.g., a key press) within the interrupt.
 Calculate the frequency of the input events.
[org 0x0100]
jmp start

; Data Storage in Code Segment


ticks dw 0 ; Timer tick count
events dw 0 ; Keypress event count
original_08h dw 0, 0 ; Store original INT 08h vector

; Timer Interrupt Handler


int08_handler:
push ax
push bx
push cx
push dx
push es
push di
push si

; Increment tick counter


inc word [ticks]

; Check for key press


mov ah, 0x01
int 0x16 ; Check keyboard buffer
jz .no_key
inc word [events] ; Count key press event
mov ah, 0 ; Clear keyboard buffer
int 0x16

Page 2
.no_key:
; Chain to original INT 08h
jmp far [original_08h]

start:
; Save original INT 08h vector
mov ax, 0x3508
int 0x21
mov [original_08h], bx
mov [original_08h+2], es

; Set custom INT 08h handler


lea dx, int08_handler
mov ax, 0x2508
int 0x21

; Wait for approximately 10 seconds


mov cx, 1820 ; Approximately 10 seconds (10 * 18.2 Hz)
.wait_loop:
mov ax, [ticks]
.loop_check:
cmp ax, [ticks] ; Wait for the next tick
je .loop_check
loop .wait_loop

; Disable interrupts to safely display results


cli

; Calculate and display frequency


mov ax, [events] ; Load event count
mov cx, 10 ; Time period in seconds
div cx ; Frequency = events / seconds

; Display result
mov bx, ax ; Store frequency in BX
call print_number ; Print the frequency

; Restore original INT 08h


mov ax, 0x2508
mov dx, [original_08h]
int 0x21

; Exit program
mov ax, 0x4C00

Page 3
int 0x21

; Routine to Print a Number (AX contains number to print)


print_number:
push ax
push bx
push cx
push dx

mov cx, 0 ; Initialize digit count


.print_loop:
xor dx, dx ; Clear DX
div word [ten] ; Divide by 10, remainder in DX
push dx ; Store remainder (digit)
inc cx ; Increment digit count
test ax, ax ; Check if number is zero
jnz .print_loop

; Print digits from stack


.print_digits:
pop dx ; Retrieve stored digit
add dl, '0' ; Convert to ASCII
mov ah, 0x0E ; Teletype output function
int 0x10 ; Print character
loop .print_digits

pop dx
pop cx
pop bx
pop ax
ret

ten dw 10 ; Constant value for division

Task 2: Change keyboard behavior to display special messages when specific keys are
pressed.
 Hook INT 09h and check for specific scan codes (e.g., F1 key).
 Display a custom message.

[org 0x0100]
jmp start

f1_msg db "F1 Key Pressed!", 0

Page 4
int09_handler:
push ax
in al, 0x60 ; Read scan code
cmp al, 0x3B ; F1 key scan code
jne .done
lea si, f1_msg
.print_msg:
lodsb
or al, al
jz .done_msg
mov ah, 0x0E
int 0x10
jmp .print_msg

.done_msg:
; Clear keyboard buffer
in al, 0x61
mov ah, al
or al, 0x80
out 0x61, al
mov al, ah
out 0x61, al

.done:
pop ax
jmp far [original_09h]

start:
; Save original INT 09h
mov ax, 0x3509
int 0x21
mov [original_09h], bx
mov [original_09h+2], es

; Set custom INT 09h handler


lea dx, int09_handler
mov ax, 0x2509
int 0x21

; Wait for key press to exit


mov ah, 0x00
int 0x16

; Restore original INT 09h


mov ax, 0x2509

Page 5
mov dx, [original_09h]
int 0x21

; Exit
mov ax, 0x4C00
int 0x21

original_09h dw 0, 0

Task 3: Chaining Multiple Handlers


Multiple custom handlers can be chained using the Interrupt Vector Table (IVT). Handlers can
pass control to the next in the chain.
 Create two custom handlers for INT 08h.
 Chain them sequentially, each performing a different task; display word counter, and toggle
character on screen.

[org 0x0100]
jmp start

; Data Storage in Code Segment


original_08h dw 0, 0 ; Store original INT 08h vector
next_handler dw 0, 0 ; Store address of the next handler in chain
counter1 dw 0 ; Task 1 (counter) storage

; Timer Interrupt Handler 1


handler1:
; Task 1: Increment counter
inc word [counter1]

; Chain to next handler


jmp far [next_handler]

; Timer Interrupt Handler 2


handler2:
; Task 2: Toggle character on screen
; Example: Change text attribute or toggle a character.
mov ah, 0x0E ; BIOS teletype function (write character to screen)
mov al, '*' ; Character to display
mov bh, 0 ; Page number (0)
mov bl, 7 ; Light cyan color (attribute)
mov cx, 1 ; Number of times to write the character
mov dx, 0x0000 ; Starting position on screen (top-left corner)
int 0x10 ; Call BIOS video interrupt

Page 6
; Chain to the original INT 08h handler
jmp far [original_08h]

start:
; Save the original INT 08h vector (timer interrupt)
mov ax, 0x3508 ; Function to get current vector for INT 08h
int 0x21
mov [original_08h], bx ; Store vector
mov [original_08h+2], es

; Set the custom handler for INT 08h (timer interrupt)


lea dx, handler1 ; Set address of our handler1
mov ax, 0x2508 ; Function to set interrupt vector
int 0x21

; Chain to handler2 (second task)


lea dx, handler2 ; Set address of our handler2
mov [next_handler], dx ; Store next handler in the chain
mov [next_handler+2], es

; Wait for a key press


mov ah, 0x00
int 0x16 ; BIOS keyboard interrupt (wait for key press)

; Restore the original INT 08h handler


mov ax, 0x2508 ; Function to restore the original vector
mov dx, [original_08h]
int 0x21

; Exit to DOS
mov ax, 0x4C00
int 0x21

Page 7

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy