-1

I have created a tsr program in nasm. It is working fine but i also have to remove it from memmory and restore all hooked interupts to original when i press 'ESC' button. This is my part of the code that runs when i press 'ESC' button.

uninst:
cli
xor ax, ax
mov es, ax
mov ax, [stari_int09_seg]
mov [es:09h*4+2], ax
mov dx, [stari_int09_off]
mov [es:09h*4], dx
sti
mov ah,49h
int 21h
iret

So i restored my int 09h that i changed to its original value and cleared my memmory with mov ah,49h
, but when i press 'ESC' my dos console becomes irresponsive. That means i did not remove my TSR the right way. My first question is am i missing something ? Are there any people who have experiance with TSR program that can really give appropriate answer.

Bozic
  • 159
  • 1
  • 12
  • 1
    For the ah,49h, int 21h, sequence, you're supposed to set ES to the starting segment of the block to be released, which is probably the CS register (the PSP = program segment prefix). Try: | push cs | pop es | mov ah,49h | int 21h | . I'm assuming this is a .COM type TSR (versus a .EXE). Also you may need to move the sti to just before the iret. Another issue is that some DOS interrupts can't be nested. – rcgldr Nov 07 '14 at 08:04
  • @rcgldr I tried what u wrote but didn't have succes. I can upload the whole code somewhere if you have time to see it – Bozic Nov 07 '14 at 20:24
  • See if this link helps. The instructions are a bit messed up, showing operands on separate lines instead of commas. [tsrs](http://www.oopweb.com/Assembly/Documents/ArtOfAssembly/Volume/Chapter_18/CH18-4.html) – rcgldr Nov 07 '14 at 21:21

2 Answers2

0

We have to put the segment of block to free into the ES segment register.

RBIL->inter61b.zip->INTERRUP.G
--------D-2149-------------------------------
INT 21 - DOS 2+ - FREE MEMORY
AH = 49h
ES = segment of block to free
Return: CF clear if successful
CF set on error
    AX = error code (07h,09h) (see #01680 at AH=59h/BX=0000h)
Notes:  apparently never returns an error 07h, despite official docs; DOS 2.1+
  code contains only an error 09h exit
DOS 2.1-6.0 does not coalesce adjacent free blocks when a block is
  freed, only when a block is allocated or resized
the code for this function is identical in DOS 2.1-6.0 except for
  calls to start/end a critical section in DOS 3.0+
SeeAlso: AH=48h,AH=4Ah
0

Are you sure DS points to the segment where you stored the original value of vector 9?
As others pointed out you need to setup ES prior to calling DOS function 49h.
You immediately do an IRET after freeing the memory. I would have expected a bunch of POP instructions because this code is part of an interrupt routine and therfore can not change any registers!

Sep Roland
  • 33,889
  • 7
  • 43
  • 76