TIP: Click on subject to list as thread! ANSI
echo: 80xxx
to: SYLVAIN LAUZON
from: GLEN MCNABB
date: 1998-02-19 21:06:00
subject: Re: i need to allocate some memory

On , Sylvain Lauzon wrote to Sergio Lo Cascio :
SL> SL> Usually val can be the lenght of the .com file divided by 16
SL> SL> And then you can allocate with int 21h/8.
SL> But would the stack space be included? So i initialize the whole segment
SL> just to be safe.
Hi Sylvain,
        You could do that. It's the easy way... Here's another...
; Program Skeleton.
org 100h
jmp start
size_stack      equ 200         ;equate of size of stack in words

start:                          ;label of starting code past data
 call deallocate                ;set stack and deallocate memory
 jc error_exit                  ;bail if it goes bad

deallocate:                     ;label deallocate memory call
;put this code prior to the stack. If you program over-uses the
;stack, it's ok, you won't need this code after you use it.
 mov dx, offset stackend        ;may have to move because of foward
                                ;referencing problems
 push dx
 pop sp                         ;new stack set
 xor dx, dx                     ;avoid 32 bit division bug in some
                                ;assembles
 mov ax, offset end_of_program  ;get pointer
 mov cx, 16                     ;get divisor
 div cx                         ;do it
 inc ax                         ;16 more bytes just in case
 mov bx, ax                     ;set up size to shrink to
 mov ah, 4ah                    ;set dos call, es should be there
                                ;already
 int 21h                        ;call dos
ret                             ;leave deallocation, carry unaffected
stack   dw      size_stack dup ??       ;declares stack area
stackend equ $                          ;equate a pointer
end_of_program:                 ;label end of program as last
; skeleton over....
Using this, you can change the value of size_stack without
affecting the program if you need. You could add in some
nifty things like error reporting and such easily enough.
Glen...
--- ProBoard v2.16 [Reg]
---------------
* Origin: NC/NEC SEWAnet, Bucolic Fair (1:3407/25)

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.