.NLIST TOC,SYM .TITLE $INIDM .SBTTL ULBLIB 004 - Initialize Dynamic memory .IDENT \V01.02\ .PSECT .LIBC. .ENABL LC,GBL ; Copyright (c) 1998 by Mentec, Inc., Nashua, NH. ; All rights reserved ; ; This software is furnished under a license for use only on a ; single computer system and may be copied only with the ; inclusion of the above copyright notice. This software, or ; any other copies thereof, may not be provided or otherwise ; made available to any other person except for use on such ; system and to one who agrees to these license terms. Title ; to and ownership of the software shall at all times remain ; in Mentec, Inc. ; ; The information in this document is subject to change without ; notice and should not be construed as a commitment by Digital ; Equipment Corporation, or Mentec, Inc. ; ; Digital and Mentec assume no responsibility for the use or ; reliability of its software on equipment which is not supplied ; by Digital or Mentec, and listed in the Software Product ; Description. ;+ ; $INIDM ; The Initialize Dynamic Memory routine establishes the initial state of the ; free dynamic memory available to the executing task. The free dynamic ; memory consists of all memory extending from the end of the task to the base ; of the Resident Monitor. ; ; R0 -> .WORD FREESP ;Address of first free dynamic memory location ; .WORD 0 ;Must be 0 ; ; CALL $INIDM ; ; R0 = size of dynamic memory ; Free memory list is initialized ; Any previously allocated blocks are deallocated. ;- .MCALL .SETTOP $INIDM:: MOV R1,-(SP) ;Save R1 MOV R0,R1 ; and the address of the free memory list .SETTOP #-2 ;Ask for all of memory SUB @R1,R0 ;Get the size BCS 10$ ;Less than we already have?!?!? MOV @R1,R1 ;Point to the free block CLR (R1)+ ;Clear the pointer to the next block TST -(R0) ;Back off a word BIC #3,R0 ;Round it to a 4 byte boundary MOV R0,@R1 ;Save the size 10$: MOV (SP)+,R1 ;Restore R1 RETURN .END