Re: Freeing DOS memory
- From: Dirk Wolfgang Glomp <spamtrap@xxxxxxxxxx>
- Date: Fri, 14 Dec 2007 23:26:24 +0100
Am Fri, 14 Dec 2007 10:45:31 -0800 (PST) schrieb Dan:
Hi, everyone, just thought I'd update with the results from using
ah=4a.
Well, it worked.
I have a half dozen DOS assembly books, but only one got it *really*
right - a book from Microsoft Press. All the others made misleading
statements that made it look like either of ah=49 or ah=4a could do
the job. They even describe those functions in such a way that I drew
that conclusion that a failure by one guaranteed a failure by the
other.
The Microsoft book makes it very clear that ah=4a is the function to
use to free unused space from a newly started program.
So thanks, again, to all.
German book from Data Becker: PC-Intern
;-- SETFREE: den nicht belegten Speicherplatz freigeben ----------------
;-- Eingabe : ES = Adresse des PSP
;-- Ausgabe : keine
;-- Register : AX, BX, CL und FLAGS werden verändert
;-- Info : Da das Stack-Segment immer das letzte Segment in einer
; EXE-Datei ist, deutet ES:0000 auf den Anfang und SS:SP
; auf das Ende des Programms im Speicher. Dadurch kann die
; Länge des Programms berechnet werden
SETFREE: mov bx, ss ;zunächst die beiden Segmentadressen
mov ax, es ;voneinander abziehen. Das ergibt die
sub bx, ax ;Anzahl der Paragraphen vom PSP bis
;zum Anfang des Stack
mov ax, sp ;da sich der Stackpointer am Ende des
add ax, 0Fh ;Stacksegments befindet, gibt sein
shr ax, 4 ;Inhalt die Länge des Stacks an
add bx, ax ;zur bisherigen Länge hinzuaddieren
mov ah, 4Ah ;neue Größe an das DOS übergeben
int 21h
ret ;zurück zum Aufrufer
...
When your programm starts, "ES" is filled with the start-segment of your
programm and SS:SP pointed to the end, so you can calculate the space
that your programm need to stay.
....
RBIL->Inter61b.zip->Interrup.g
--------D-2148-------------------------------
INT 21 - DOS 2+ - ALLOCATE MEMORY
AH = 48h
BX = number of paragraphs to allocate
Return: CF clear if successful
AX = segment of allocated block
CF set on error
AX = error code (07h,08h) (see #01680 at AH=59h/BX=0000h)
BX = size of largest available block
Notes: DOS 2.1-6.0 coalesces free blocks while scanning for a block to
allocate
.COM programs are initially allocated the largest available memory
block, and should free some memory with AH=49h before attempting any
allocations
under the FlashTek X-32 DOS extender, EBX contains a protected-mode
near pointer to the allocated block on a successful return
SeeAlso: AH=49h,AH=4Ah,AH=58h,AH=83h
--------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
--------D-214A-------------------------------
INT 21 - DOS 2+ - RESIZE MEMORY BLOCK
AH = 4Ah
BX = new size in paragraphs
ES = segment of block to resize
Return: CF clear if successful
CF set on error
AX = error code (07h,08h,09h) (see #01680 at AH=59h/BX=0000h)
BX = maximum paragraphs available for specified memory block
Notes: under DOS 2.1-6.0, if there is insufficient memory to expand the
block
as much as requested, the block will be made as large as possible
DOS 2.1-6.0 coalesces any free blocks immediately following the block
to be resized
SeeAlso: AH=48h,AH=49h,AH=83h
Ralf Browns Interrupt List(RBIL)
http://www.pobox.com/~ralf
http://www.pobox.com/~ralf/files.html
ftp://ftp.cs.cmu.edu/afs/cs.cmu.edu/user/ralf/pub/
.....
Dirk
.
- References:
- Freeing DOS memory
- From: Dan
- Re: Freeing DOS memory
- From: Dan
- Re: Freeing DOS memory
- From: pete
- Re: Freeing DOS memory
- From: Jim Higgins
- Re: Freeing DOS memory
- From: Dan
- Freeing DOS memory
- Prev by Date: Re: Looking for a Library Disassembler for X86
- Next by Date: is there an assembler with any library interface?
- Previous by thread: Re: Freeing DOS memory
- Next by thread: Re: Freeing DOS memory
- Index(es):
Relevant Pages
|
|