Lab 14 Sol
Lab 14 Sol
Laboratory Manual
for
Computer Organization and Assembly Language Programming
Page 1
OBJECTIVES:
Understand Infinite Loop-Based Animation. Learn to implement an animated effect where a symbol
(star) moves continuously within a specific column of the console, simulating a falling motion
Implement Keyboard-Controlled Thread Creation: Develop the ability to dynamically start new threads
for falling stars using keyboard input, with each thread targeting a different column.
Master Multithreaded Column Management: Understand how to schedule and manage multiple
threads, each working independently to display animations in different columns, using timer-based
multitasking.
Task 1: Write a function fallingStar that takes column number as parameter and prints a
star moving in that column.
For example, if colNo is 80, your function will print a star in column 80, falling from row 0 to
row 24 (with some delay). After reaching row 24, it will again appear on 1st row and start falling
again, in an infinite loop.
fallingStar:
push bp
mov bp, sp
fallingLoop:
push ax
push bx
push cx
push dx
Page 2
shl dx, 7 ; Multiply by 160 to get row offset
add dx, si ; Add column offset
mov byte [es:dx], 0x20 ; Write space to clear star
skipClear:
; Draw star in the current row
mov bx, [bp-2] ; Load current row
mov dx, bx
shl dx, 7 ; Multiply by 160 to get row offset
add dx, si ; Add column offset
mov byte [es:dx], 0x2A ; Write '*' in the current column
mov byte [es:dx+1], 0x07 ; Attribute byte (white text)
continueFall:
; Delay loop
mov cx, 5000 ; Arbitrary delay count
delayLoop:
loop delayLoop
pop dx
pop cx
pop bx
pop ax
jmp fallingLoop ; Infinite loop
mov sp, bp
pop bp
ret
Task 2: Write a program that starts a new thread of falling star if the user presses key ‘8’.
[org 0x0100]
Page 3
jmp start
exit: pop si
Page 4
pop cx
pop bx
pop ax
pop bp
ret 6
; Main program
start:
; Hook timer interrupt
xor ax, ax
mov es, ax
cli
mov word [es:8*4], timer
mov [es:8*4+2], cs
sti
Page 5