Bozic
Bozic

Reputation: 157

Nasm Print String in TSR program

I am trying to print string in my program. When i put my instructions

mov ah,9h
mov dx,poruka
int 21h

before call _inst_09 it prints well. But when i print inside my code like shown below it prints weird stuff and characters. This is picture of program working.This is picture of working program. String is printed well

asddThis is picture of program not working when i print my string inside the code

This is my TSR code

org 100h

NULL           equ 000h
ESC            equ 001h         
KBD            equ 060h         

EOI            equ 020h         
Master_8259    equ 020h
zelena  equ 02h                             

main:
    mov ah,9h
mov dx,poruka
int 21h
call _inst_09

_inst_09:
cli
xor     ax, ax
mov     es, ax

;mov    ax, [stari_int09_off]

mov     bx, [es:09h*4]
mov     [stari_int09_off], bx
mov     [es:60h*4], bx ; U int60h ubacujemo off od int9h    
mov     bx, [es:09h*4+2]
mov     [stari_int09_seg], bx
mov     [es:60h*4+2], bx ; U int60h ubacujemo seg od int9h

mov     dx, tastatura
mov     [es:09h*4], dx
mov     ax, cs
mov     [es:09h*4+2], ax
sti

mov ax,3100h
mov dx,500
int 21h
ret

tastatura:
push    ax
in      al, KBD             
mov    [kbdata], al
cmp byte[kbdata],20h
je .lup
cmp byte[kbdata],ESC
je .krj
mov     al, EOI             
out     Master_8259, al     
pop     ax
int 60h ; Vracamo stari interupt 9h
iret
.lup:
mov ax,0b800h ;dont forget 0 before b
mov es,ax
mov bx,word[video]
mov ah, 02h
int 1ah

mov al,dh
mov byte [es:100+bx],al ;also dont forget the byte thing
;inc byte[video]
;inc byte[video]
mov     al, EOI             
out     Master_8259, al     
pop     ax
iret
.krj:
mov ah,9h
mov dx,poruka
int 21h
ret

stari_int09_seg: dw 0
stari_int09_off: dw 0


kbdata: db 0                            
key: db 0
video: dw 100

poruka: db 'Poruka.$'

%include "ekran.asm"

Here is the deal with code. This is a TSR program, so it terminates and stays resident when i run it. When i press esc button it should print my string on the screen(it jumps on .krj label) but it will show something like you see on the 2nd picture. When i put my instructions before call _inst09 like i said before it will print my string lik in the 1st picture.
I think that somehow my string address has changed and that is why it is not working but i cannot figure it out.
I would appreciate if you could give me a direct answer regarding to my code.

Upvotes: 0

Views: 636

Answers (2)

Sep Roland
Sep Roland

Reputation: 39271

With je .krj you jump to a routine that calls a DOS service for printing. You cannot use DOS services from within an interrupt handler because DOS might have been occupied when the interrupt was triggered.
Simplest solution here is to output to the screen using the BIOS teletype function 0Eh. Why not even write to the screen at segment 0B800h yourself since you're doing it already somewhere else?

Upvotes: 1

Dirk Wolfgang Glomp
Dirk Wolfgang Glomp

Reputation: 113

If we jump to .krj, then we also have to terminate the ISR with sending an EOI, popping ax and end with iret. The last "ret" instruction is wrong.

Upvotes: 0

Related Questions