0% found this document useful (0 votes)
29 views2 pages

l10q2 Asm

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

l10q2 Asm

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

[org 0x0100]

jmp start

; subroutine to clear the screen


clrscr:
push es
push ax
push di
mov ax, 0xb800
mov es, ax ; point es to video base
mov di, 0 ; point di to top left column

nextloc:
mov word [es:di], 0x0720 ; clear next char on screen
add di, 2 ; move to next screen location
cmp di, 4000 ; has the whole screen cleared
jne nextloc ; if not, clear next position
pop di
pop ax
pop es
ret

; subroutine to print a string at a desired screen location


printstr:
push bp
mov bp, sp
push es
push ax
push bx
push cx
push dx
push si
mov ax, 0xb800
mov es, ax ; point es to video base
mov bx, [bp+4] ; load attribute in bx
mov cx, [bp+6] ; load string length in cx
mov si, [bp+8] ; load string address in si
mov dx, [bp+12] ; load row in dx
mov ax, dx ; load row into ax
mul byte 80 ; multiply with 80 columns per row
add ax, [bp+10] ; add column to get screen offset
shl ax, 1 ; turn into byte offset
mov di, ax ; point di to required location

nextchar:
lodsb ; get next character
or al, al ; check for end of string
jz done ; if zero, jump to done
mov ah, bl ; copy attribute to ah
mov [es:di], ax ; show this char on screen
add di, 2 ; move to next screen location
jmp nextchar ; loop back for next character

done:
pop si
pop dx
pop cx
pop bx
pop ax
pop es
pop bp
ret 8 ; return, popping the four argument bytes

; original keyboard interrupt handler


oldkeyhandler:
push ax
push bx
push cx
push dx
mov ah, 0 ; read keystroke
int 0x16 ; call BIOS
cmp ah, 0 ; is this the first keystroke?
je clearscreen ; if yes, clear the screen
cmp al, 'a' ; is it the letter a?
je akeypressed ; if yes, mark that a key is pressed
jmp calloriginal ; otherwise, pass the key to the original ISR
akeypressed:
mov [akey], 1 ; mark that a key is pressed
jmp calloriginal ; pass the key to the original ISR

; clear screen when 'A' key is pressed


clearscreen:
call clrscr ; clear the screen
mov [akey], 0 ; mark that 'A' key is not pressed
jmp exitprogram ; exit the program

; delay function
delay:
push cx
push dx
mov cx, 0x00FF ; delay counter
mov dx, 0x0FFFF

You might also like