Chapter 8 and 9 Codes
Chapter 8 and 9 Codes
Qno1
[org 0x0100]
jmp start
isTSR: dw 0
oldISR: dd 0
;--------------------------------------------------------------------------
jnz chain
cmp word [cs:isTSR], 0 ;Agar tw humari myISR TSR ban chuki hai, phir
ab kisi aur naye program ko TSR nahi banney dena
jz makeitTSR ;Lekin agar humari myISR TSR nahi bani, tw pehley
usey TSR banao
;---------------------------------------------------------------------------
jmp start
address: dd 0
;-----------------------------------------------------------------------------------------------------------------
;Clear Screen
clrscr: push bp
mov bp, sp
pusha
push es
cld
rep stosw
pop es
nearReturn: popa
pop bp
ret 2
farReturn: popa
pop bp
retf 2
popa
pop bp
add sp, 2
iret
;-----------------------------------------------------------------------------------------------------------------
push 0
call clrscr ;Near Call
push 0
call far [address] ;Far Call
push 0
int 80h ;Interrupt Call (Extended Far Call)
Qno3
[org 0x0100]
jmp start
XISR_Offset: dw 0x0000
XISR_Segment: dw 0x0000
N: dw 0x80
;-----------------------------------------------------------------------------------------------------------------
hooker: push bp
mov bp, sp
sub sp, 4 ;Making two local variables, one for old
offset and one for old segment of the ISR previously hooked at N
pusha
push es
xor ax, ax
mov es, ax
;First of all saving the offset, segment of the ISR previously hooked at N
return: pop es
popa
add sp, 4
pop bp
ret 6
;--------------------------------------------------------------------------------------------------------------------
;---------------------------------------------------------------------------------------------------------------------
XISR: pushf
call 0:0
popf
ret
;---------------------------------------------------------------------------------------------------------------------
call hooker
[org 0x0100]
jmp start
call borderAsterisk
;Clear Screen
clrscr: mov ax, 0xb800
mov es, ax
xor di,di
mov ax,0x0720
mov cx,2000
cld
rep stosw
ret
;Delay
delay: pusha
mov cx, 0xFFFF
b1: loop b1
popa
ret
borderAsterisk: push bp
mov bp, sp
pusha
mov di, 0
call delay
mov [es:di], bx
call delay
add di, 2
loop l1
sub di, 2
call delay
mov [es:di], bx
call delay
loop l2
call delay
mov [es:di], bx
call delay
sub di, 2
loop l3
add di, 2
LefttoTop: mov cx, 25
call delay
mov [es:di], bx
call delay
loop l4
return: popa
pop bp
ret
;--------------------------------------------------------------------------------
; ALTERNATE SOLUTION
; Solution to this problem was developed by https://github.com/farhana1i
;--------------------------------------------------------------------------------
; jmp main
; pop di
; pop ax
; pop es
; ret
; ; to print asteric
; ; DI == position
; printAsterick:
; push ax
; push es
; checkUp:
; cmp byte [row], 24
; JNE nextCmp
; mov byte [isLeft], 0
; mov byte [isRight], 0
; mov byte [isTop], 1
; mov byte [isBottom], 0
; jmp update
; nextCmp:
; cmp byte [col], 158
; JNE update
; checkRight:
; cmp byte [row], 24
; JNE update
; mov byte [isLeft], 0
; mov byte [isRight], 1
; mov byte [isTop], 0
; mov byte [isBottom], 0
; jmp update
; update:
; cmp byte [isLeft], 1
; JNE checkRightFlag
; add di, 2
; add byte [col], 2
; jmp printScreen
; checkRightFlag:
; cmp byte [isRight], 1
; JNE checkUpFlag
; sub di, 2
; sub byte [col], 2
; jmp printScreen
; checkUpFlag:
; cmp byte [isTop], 1
; JNE checkDownFlag
; sub di, 160
; sub byte [row], 1
; jmp printScreen
; checkDownFlag:
; cmp byte [isBottom], 1
; JNE printScreen
; add di, 160
; add byte [row], 1
; jmp printScreen
; printScreen:
; mov ah, 0x07 ; attribute
; mov al, '*'
; mov word [es: di], ax
; pop es
; pop ax
; ret
; exitTimer:
; mov al, 0x20 ; send EOI
; out 0x20, al
; pop ax
; iret
; main:
; ;call clrscr ; to clear screen
; mov di, 0
; xor ax, ax
; mov es, ax
; ; hook interrupt
; cli
; mov word [es: 8*4], timer
; mov [es: 8*4+2], cs
; sti
—----------------------------------------------------------------------------------------------------------------------------------------
Qno 8
; Solution to this problem was developed by https://github.com/farhana1i
[org 0x0100]
jmp main
pop di
pop ax
pop es
ret
pop di
pop cx
ret
cld
rep movsw ; move data from video memory to buffer
pop ds
pop es
pop di
pop si
pop cx
pop ax
pop bp
ret
; load buffer
load_buffer:
push bp
mov bp, sp
push ax
push cx
push si
push di
push es
push ds
cld
rep movsw ; load buffer in video memory
pop ds
pop es
pop di
pop si
pop cx
pop ax
pop bp
ret
nextCmp:
cmp al, 10011101b ; snap code of ctrl == 29
JNE noMatch
noMatch:
pop ax
jmp far [cs:oldisr] ; CALL the original ISR
exit:
mov al, 0x20 ; send EOI
out 0x20, al
pop ax
iret
main:
xor ax, ax
mov es, ax
; save old keyboard isr
mov ax, [es:9*4]
mov [oldisr], ax
mov ax, [es:9*4+2]
mov [oldisr+2], ax
Qno11
;Write a TSR to calculate the current typing speed of the user.
;Current typing speed is the number of characters typed by the user in the last five seconds.
;The speed should be represented by printing asterisks at the right border (80th column) of the screen
;starting from the upper right to the lower right corner (growing downwards).
;Draw n asterisks if the user typed n characters in the last five seconds. The count should be updated
every second.
;----------------------------------------------------------------------------------------------------------------------------------
;-----------------------------------------------------------------------------------------------------------------------------------
[org 0x0100]
jmp start
tCount: dw -1 ;Note: The tCount of first second is initialized to -1 for one time because
when you type the command and press ENTER
; then the program gets loaded. And it takes you
a few milliseconds to release the ENTER key
; and since the program was loaded before, it
counts this release of ENTER key as one. So this release count
; is ignored by initializing the count to -1
iNo : dw 0
;-----------------------------------------------------------------------------------------------------------------
;Clear Screen
clrscr: pusha
push es
cld
rep stosw
pop es
popa
ret
;-----------------------------------------------------------------------------------------------------------------
mov al, 80
mul byte [cs:location]
add ax, 159
shl ax, 1
mov di, ax
cmp cx, 0
jle return
l1: mov byte [es:di], '*'
inc byte [cs:location]
add di, 160
loop l1
return: pop es
popa
ret
;-----------------------------------------------------------------------------------------------------------------
CTS: pusha
;These lines will execute for the very first five seconds
cmp word [cs:iNo], 10
jz l2
jmp EOI2
;Shifting the counts towards the right, to create a space for this current
second
mov dx, 0
mov ax, [cs:count + 2]
add dx, ax
mov [cs:count], ax
jmp a1
call clrscr
exit: popa
iret
;-----------------------------------------------------------------------------------------------------------------
;Keyboard ISR
kbisr: push ax
in al, 0x60
shl al, 1
jnc EOI1
inc word [cs:tCount] ;If a key is released, only then increase the count
pop ax
iret
;-----------------------------------------------------------------------------------------------------------------
mov bx, 0
call clrscr
sti