% Section 2.3.2, Program D / Subroutine AGC % [AGC = Allocation / Garbage Collection] % Author Chan Vinh VONG % Draft Version 2012 May 08th % % This is a helper subroutine for block allocation and garbage % collection. Whenever notation X <= AVAIL or AVAIL <= X is encountered % in an algorithm, use :AGC:A and :AGC:GC resp. for allocating a new % block and garbage collect a freed block. % % Remarks: % - about memory allocation: the 1st octa of each free block indicates % where the next free block is located. If that pointer is null then % the next free block is the next neighbour block, else it is the % address of the next free block, which by the way could be the next % neighbour too (we just avoid the overhead of setting up the memory % at startup because the current implementation sets all memory to % zero). % - about memory garbage collection: the 1st octa of the garbage % collected block is replaced w/ the address of the current AVAIL % block % % Global Variables: % :AVAIL stack % PREFIX AGC: BLK IS 8*3 % block size block IS $0 temp IS $1 % Block <= AVAIL % returns the address of an allocated block % also updates the :AVAIL pointer % % Calling Sequence: % PUSHJ t,:AGC:A % t = address of new block % A IS @ SET block,:AVAIL % allocate LDOU temp,:AVAIL,0 % update :AVAIL PBZ temp,nxt SET :AVAIL,temp % follow the link to the next neighbour JMP ret nxt ADDU :AVAIL,:AVAIL,BLK % take neighbour block ret POP 1,0 % AVAIL <= Block % input: address of block to GC % returns nothing % also updates the :AVAIL pointer % % Calling Sequence: % t+1 <- address of block to free % PUSHJ t,:AGC:GC % GC IS @ SET temp,:AVAIL STOU temp,block,0 SET :AVAIL,block POP 0,0 PREFIX :