% Section 2.2.3, Exo 3 % Author Chan Vinh VONG % Draft Version 2012 April 8th % % Deletes the top of the stack (if not empty else UNDERFLOW), and put % the freshly deleted node into the storage pool of available nodes % % /!\ requires S223E2.mms for some definitions % /!\ requires lib/out.mms for output messages % % Calling Sequence: % PUSHJ $0,DELETE % TETRA T-high % TETRA T-low % % Entry Conditions: % The two tetras hold the link variable to the stack. % % Exit Conditions: % The deleted node is put back in the storage pull. % The top of the stack is updated. % The value of the deleted INFO is returned. % % Exceptions: % UNDERFLOW if the stack is empty % PREFIX DELETE: LOCT IS $0 % location of top of stack T IS $1 % top of stack temp IS $2 P IS $3 :DELETE GET temp,:rJ LDHT LOCT,temp,0 LDTU temp,temp,4 OR LOCT,LOCT,temp LDOU T,LOCT BZ T,9F % Is stack empty? SET P,T LDOU T,P,:dLINK % T <- LINK(P) STOU T,LOCT STOU :AVAIL,P,:dLINK % LINK(P) <- AVAIL SET :AVAIL,P % AVAIL <- P LDOU $0,P,:dINFO POP 1,2 9H GET $0,:rJ PUSHJ $1,:OUTPUT:OVERFLOW PUT :rJ,$0 POP 0,2 PREFIX :