-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmemalloc.asm
80 lines (57 loc) · 1.78 KB
/
memalloc.asm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
;
; memory management routines
;
.DOSSEG
.MODEL small, c, os_dos
.386
.CODE
INCLUDE constant.inc
memAlloc proc near public
; input: AX = # of paragraphs required
; output: AX = segment of block to use
push bx
mov bx, ax
mov ah, 48h
int 21h
pop bx
ret
memAlloc endp
FreeMem proc
; deallocate a memory block
; input AX=segment of block to free
; output CY set if failure
push ax
push es
mov es, ax
mov ah, 49h
int 21h
pop es
pop ax
ret
Freemem endp
;-- SETFREE: Release memory not used ----------------
;-- Input : ES = address of PSP
;-- Output : none
;-- Register : AX, BX, CL and FLAGS are changed
;-- Info : Since the stack-segment is always the last segment in an
; EXE-file, ES:0000 points to the beginning and SS:SP
; to the end of the program in memory. Through this the
; length of the program can be calculated
; call this routine once at the beginning of the program to free up memory
; assigned to it by DOS.
setFree proc near public
mov bx,ss ;first subtract the two segment addresses
mov ax,es ;from each other. The result is
sub bx,ax ;number of paragraphs from PSP
;to the beginning of the stack
mov ax,sp ;since the stackpointer is at the end of
mov cl,4 ;the stack segment, its content indicates
shr ax,cl ;the length of the stack
add bx,ax ;add to current length
inc bx ;as precaution add another paragraph
mov ah,4ah ;pass new length to DOS
int 21h
@@:
ret ;back to caller
setFree endp
end