Lab 11 Sol.
Lab 11 Sol.
Laboratory Manual
for
Computer Organization and Assembly Language Programming
Page 1
OBJECTIVES:
Write a program to make an asterisk travel the border of the screen, from upper left to upper
right to lower right to lower left and back to upper left indefinitely, making each movement after
one second. You are not allowed to write any loop in your program. The Timer will move the
star by one cell only. Do not lose the previous content of the cell.
Instructions:
1. Hook the timer interrupt (INT 08h) to control the asterisk’s movement.
2. Set up a delay of approximately one second using the timer’s count.
3. Use a buffer to save the content of the screen cell before placing the asterisk, restoring it
after the asterisk moves to the next cell.
4. Avoid any explicit loop in your code to manage the movement.
[org 0x100]
jmp start
Page 2
; Calculate the next position for the asterisk along the screen border
call move_asterisk
skip_movement:
; Send End of Interrupt (EOI) to the PIC
mov al, 0x20
out 0x20, al
pop di
pop es
pop bx
pop ax
ret
Page 3
; Right column: Top to bottom
cmp di, 3840 ; Bottom right corner of the screen
jl move_down
move_right:
add di, 2 ; Move right one position
jmp save_position
move_down:
add di, 160 ; Move down one row
jmp save_position
move_left:
sub di, 2 ; Move left one position
jmp save_position
bottom_row:
mov di, 4000 ; Move to bottom row left
jmp move_left
save_position:
mov [asterisk_pos], di
ret
start:
; Save the old timer ISR address
mov ax, 0
mov es, ax ; Point ES to IVT base
mov ax, [es:8*4] ; Get old ISR offset
mov word [old_timer_isr], ax
mov ax, [es:8*4 + 2] ; Get old ISR segment
mov word [old_timer_isr + 2], ax
Page 4
; Install our custom timer ISR
cli ; Disable interrupts
mov word [es:8*4], timer_isr ; Set new ISR offset
mov word [es:8*4 + 2], cs ; Set new ISR segment
sti ; Enable interrupts
; Terminate program
mov ax, 0x4C00
int 0x21
Task 2: Adding User Control to Start/Stop the Animation and Keypad Filtering
Update previous program, star should start moving (from its previous position, initial position
will be top left of screen) if user enters Left Shift key and it should stop on Right Shift Key.
Other applications should work fine along with this functionality. Both shifts should work
properly on command prompt. Number keys at the right side of keypad should not work on
command prompt but number keys on top of the keypad should work properly.
Instructions:
1. Hook the keyboard interrupt (INT 09h) to monitor Shift key presses and enable or disable
the animation accordingly.
2. Track the asterisk’s current position so it resumes from the last stopped position.
Page 5
3. Filter inputs to disable the numeric keypad keys in the command prompt but keep the
top-row number keys functional.
4. Test to verify the functionality of both Shift keys, ensuring the asterisk movement
responds accurately and does not affect other command prompt operations.
[org 0x100]
jmp start
skip_animation:
mov al, 0x20
out 0x20, al
pop es
pop bx
pop ax
jmp far [cs:old_timer_isr]
Page 6
; Keyboard interrupt handler
keyboard_isr:
push ax
push es
in al, 0x60 ; Read scancode from keyboard port
cmp al, 0x2A ; Left Shift press
je enable_animation ; Start animation
cmp al, 0x36 ; Right Shift press
je disable_animation ; Stop animation
jmp original_handler
enable_animation:
mov byte [animation_on], 1
jmp end_kb_isr
disable_animation:
mov byte [animation_on], 0
jmp end_kb_isr
filter_key:
jmp end_kb_isr ; Ignore the key by jumping to end
original_handler:
pop es
pop ax
jmp far [cs:old_kb_isr] ; Chain to original keyboard ISR
end_kb_isr:
mov al, 0x20
out 0x20, al
pop es
pop ax
iret ; Return from interrupt
start:
; Hook timer and keyboard interrupts and stay resident
xor ax, ax
mov es, ax
Page 7
mov ax, [es:9*4]
mov [old_kb_isr], ax
mov ax, [es:9*4+2]
mov [old_kb_isr+2], ax
; Stay resident
mov dx, start
add dx, 15
mov cl, 4
shr dx, cl
mov ax, 0x3100
int 0x21
Practice
Task 2: Enable Background Functionality
Update the previous program: Star should keep moving, other applications (e.g. AFD etc) should
work properly.
Instructions:
Page 8