Category : Files from Magazines
Archive   : PJ92.ZIP
Filename : MALLOC.ASM

 
Output of file : MALLOC.ASM contained in archive : PJ92.ZIP
title malloc
include asm.inc

public calloc
public free
public malloc

.const
ertx_malloc_range db 'malloc out of range',0

.code
extn ms_dos_strerror,set_strerror


;; calloc
;
; entry CX requested byte count (1..FFF0)
; exit ES:DI storage pointer
; AX actual byte count
; Cf if no storage
;
calloc proc
call malloc ; allocate storage
jc cal1

pushm ax,cx,di ; zero storage
mov cx,ax
movx ax,0
shr cx,1
rep stosw
popm di,cx,ax
cal1: ret
calloc endp


;; free
;
; entry ES:DI storage pointer (OK if NULL)
; exit ES:DI NULL
; Cf if bad pointer
; uses AX
;
free proc
mov ax,es
or ax,di
jz fee1 ;\ if NULL pointer - ignore call

mov ah,49h
call ms_dos_strerror

mov di,NULL_POINTER ; return NULL (don't modify flags)
mov es,di

fee1: ret
free endp


;; malloc
;
; entry CX requested byte count (1..FFF0)
; exit ES:DI storage pointer
; AX actual byte count
; Cf if no storage
;
malloc proc
jcxz mal2 ; if byte count out of range
mov ax,cx
add ax,15
jc mal2 ; if byte count out of range
and al,0F0h

pushm ax,bx ; convert byte count to paragraph cnt
shr ax,1
shr ax,1
shr ax,1
shr ax,1
mov bx,ax

mov ah,48h ; request memory from dos
call ms_dos_strerror
jc mal1 ; if not enough memory
mov es,ax
movx di,NULL_POINTER

mal1: popm bx,ax
ret

mal2: lea ax,ertx_malloc_range
jmp set_strerror
malloc endp

end


  3 Responses to “Category : Files from Magazines
Archive   : PJ92.ZIP
Filename : MALLOC.ASM

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/