%%off PREFIX :Free: Rover IS :Allocate:Rover Base IS :Allocate:Base Avail IS :Allocate:Avail P0 IS $0 Parameter Right IS $1 Left IS $2 Previous IS $3 n IS $4 P1 IS $5 F IS $6 B IS $7 nm1 IS $8 n1 IS $9 t IS $10 %%on Size IS Base Offsets to access \.{Size} field, :Free ADDU Right,Base,4 \qquad \.{Right} field, ADDU Left,Base,8 \qquad \.{Left} field, SUBU Previous,Base,8 \qquad and the preceeding \.{OCTA}. SUBU P0,P0,Left Make $P_0$ the relative address of the block. LDTU n,Size,P0 \ul{\sl D1.} $n\is \.{Size}(P_0)$. ADDU P1,P0,n $P_1\is P_0+n$ LDTU F,Right,P1 $F\is \.{Right}(P_1)$ LDOU nm1,Previous,P0 Get size of preceeding block. BEV F,D4 To D4 if block $P_1$ is free. D2 BEV nm1,D7 \ul{\sl D2.} To D7 if preceeding block is free. D3 LDTU F,Left,Avail \ul{\sl D3.} $F\is\.{Left}(\.{Avail})$. SET B,Avail $B\is\.{Avail}$. JMP D5 D4 LDTU n1,Size,P1 \ul{\sl D4.} ADD n,n,n1 $n\is n+ \.{Size}(P_1)$. LDTU B,Left,P1 $F\is \.{Left}(P_1)$ CMP t,P1,Rover CSZ Rover,t,Avail If $P_1 = \.{Rover}$, set $\.{Rover}\is \.{Avail}$. ADDU P1,P1,n1 $P_1\is P_1+ \.{Size}(P_1)$. BEV nm1,D6 To D6 if preceeding block is free. D5 STTU F,Right,P0 \ul{\sl D5.} $\.{Right}(P_0)\is F$ (insert $P_0$). STTU B,Left,P0 $\.{Left}(P_0)\is B$. STTU P0,Right,B $\.{Right}(B)\is P_0$. STTU P0,Left,F $\.{Left}(F)\is P_0$. JMP D8 D6 STTU F,Right,B \ul{\sl D6.} $\.{Right}(B)\is F$ (delete $P_1$). STTU B,Left,F $\.{Left}(F)\is B$. D7 ADD n,n,nm1 \ul{\sl D7.} Add size of preceeding block. SUBU P0,P0,nm1 Move $P_0$ to the preceeding block. D8 STTU n,Size,P0 \ul{\sl D8.} $\.{Size}(P_0)\is n$. STOU n,Previous,P1 Store $n$ to last \.{OCTA} of block. POP 0,0 %%off PREFIX :