I try to write my own keyboard interrupt handler (DOS is used), which only writes a message on the screen. When keyboard is not pressed, there another message is printed without end (so there is no way to stop program normally, but it doesn't matter). When lines of DOS interrupt in MYTASK routine are comented, interrupt handler works well, but since they are uncommented, my program crashes ("illegal instruction encountered"). Where could I made a mistake?
DOSSEG
.MODEL TINY
.STACK 100h
.DATA
TaskMessage DB 13,10,'Now task executed',13,10,'$'
IHandlerMessage DB 13,10,'Now interrupt handler executed',13,10,'$'
KEEP_CS DW 0
KEEP_IP DW 0
.CODE
mov ax,@Data
mov ds,ax
jmp beg
mytask proc far
infiloop:
;mov ah,09h
;mov dx,OFFSET TaskMessage ; program fails when these 3 lines
;int 21h ; are uncommented
cmp bx,bx
je infiloop
ret
mytask endp
beg:
mov AH,35h
mov AL,09h
int 21h
mov KEEP_CS, ES
mov KEEP_IP, BX ; here I save address of old interrupt handler
CLI
push DS
mov dx, offset myint
mov ax, seg myint
mov ds,ax
mov AH,25h
mov AL,09h
int 21h ; here I set new interrupt handler
pop DS
STI
call mytask ; here I start mytask
jmp end123
myint proc far ; my keyboard interrupt handler
push ds
push ax
push dx
push cx
mov ah,09h
mov dx, offset IHandlerMessage
int 21h
pop cx
pop dx
pop ax
pop ds
push ax
mov al,20h
out 20h,al
pop ax
iret
myint endp
end123:
CLI
push DS
mov DS, [KEEP_CS]
mov DX, [KEEP_IP]
mov AH,25h
mov AL,09h
int 21h ; here I set old interrupt handler again, though it is
pop DS ; not needed in this program
STI
mov ah,4ch
int 21h
END