.NLIST TOC,SYM .TITLE $RLCB .SBTTL ULBLIB 006 - Release Core Block .IDENT \V01.01\ .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. ;+ ; $RLCB ; The Release Core Block routine releases a block of previously ; allocated dynamic memory to the free memory list, which is sequentially ; ordered by the memory addresses of the blocks themselves. ; ; R0 -> free memory listhead ; R1 = the size (in bytes) of the block to be released ; R2 = the address of the block to be released ; ; CALL $RLCB ; ; R0, R1, and R2 are destroyed. ; The memory block is released. ; If possible, the block is merged with adjacent blocks. ;- $RLCB:: JSR R5,$SAVRG ;Save non-volatile registers ADD #3,R1 ;Round up to next double- BIC #3,R1 ; word boundary BEQ 5$ ;If zero, we're done... 1$: MOV R0,R4 ;Save previous block MOV @R0,R0 ;Get new block BEQ 2$ ;Link to the end of the list CMP R2,R0 ;Compare the addresses BHI 1$ ;Keep looking until lower 2$: MOV R2,@R4 ;Just link it for now MOV R0,(R2)+ ; because we'll check for merges MOV R1,@R2 ; later 3$: MOV (R4)+,R2 ;Get the address of the previous BEQ 5$ ;Branch if done MOV R2,R3 ;Copy it SUB @R4,R3 ;Subtract the top from it SUB R4,R3 ; BCC 4$ ;If carry set, we can merge them MOV (R2)+,-(R4) ;Squeeze out the second block ADD @R2,2(R4) ; adjust the size BR 3$ ; and return to try the next block 4$: MOV R2,R4 ;Can't merge. Just get next block CMP R4,R0 ; and return for another try, BLO 3$ ; unless done 5$: RETURN .END