% Section 2.2.3, Exo.2 % Author Chan Vinh VONG % Draft Version 2012 March 20th % Refined 2012 April 6th % % We are dealing with an AVAIL Chain of Nodes and multiple Stacks of % Nodes alltogether in a Storage Pool of Nodes. % % The structure for one Node is: % % >|<-----OCTA----->|< % +----------------+ % (BA+0) | LINK | % +----------------+ % (BA+8) | INFO | % +----------------+ % % The size of a Node (or the distance between 2 consecutive allocated % nodes) is thus +16 bytes. % % A noticeable change between MIX and MMIX for this exercise is about % how to make the calling sequence. % % In MIX, we have (V1e3/p.269): % % JMP INSERT % NOP T % % This technique writes a data in what is now considered in MMIX as the % Text Segment. The closest equivalent in MMIX would be a variant of % V1F1/p.54: % % PUSHJ $0,INSERT % TETRA T-high % TETRA T-low % % In order to have an absolute address, we put in two consecutive tetra % instructions, the first tetra holding the high part of the octa. % We thus have to put the link variable T in the Text Segment and not % in the Data Segment, nor in a GREG (for the sake of this exercise). % % In order to test the INSERT method, we set up: % - a storage pool already used be 3 stacks % dLINK IS 8*0 % d stands for delta, to be used for relative addressing dINFO IS 8*1 dNODE IS 8*2 % % Calling Sequence: % % $1 <- INFO to put in the new node % PUSHJ $0,INSERT % TETRA T-high % TETRA T-low % % Entry Conditions: % $1 = information to be put into the INFO field of a new node % % Exit Conditions: % The stack whose pointer is the link variable T has the new node % on top % % Exceptions: % Overflow if there is no more AVAILable node can be allocated % PREFIX INSERT: INFO IS $0 P IS $1 link IS $2 LOCT IS $3 T IS $4 temp IS $5 :INSERT SET P,:AVAIL LDOU link,P,:dLINK BZ link,8F % will we overflow? SET :AVAIL,link % update AVAIL STOU INFO,P,:dINFO % INFO(P) <- info GET temp,:rJ % get the address of the link variable LDHT LOCT,temp,0 LDTU temp,temp,4 OR LOCT,LOCT,temp LDOU T,LOCT STOU T,P,:dLINK % LINK(P) <- T STOU P,LOCT % T <- P JMP 9F 8H GET $0,:rJ PUSHJ $1,:OVERFLOW PUT :rJ,$0 9H POP 0,2 % skip the 2xTETRA after rJ PREFIX :