;Alto->8086 small-c compiler rev 2.0 C←CODE SEGMENT $INCLUDE(8086LIB.D) $INCLUDE(alloc.DEC) ASSUME CS:C←CODE, DS:C←DATA ; #include "alloc.h" ; extern int end; /* See endml.asm; end of static storage */ ; extern Zero(); ; extern Usc(); ; extern CallSwat(); ; extern UMax(); ; extern ReturnLoc(); ; extern MyFrame(); ; struct ZN *GetAll() { ←GetAll: PUSH BP MOV BP,SP ; char *z; ; int len; ; struct ZN *zn; ADD SP,0FFFAX ; z = (char *) (((int) &end+1)&(-2)); LEA BX,←end INC BX AND BX,0FFFEX ; ←z ← BX MOV [BP-2],BX ; len = zoneTop - ((int) z); ; BX ← ←z MOV BX,[BP-2] MOV CX,0CFFEX SUB CX,BX ; ←len ← CX MOV [BP-4],CX ; if (Usc(len, 0x7FFF) > 0) { MOV BX,07FFFX ; CX ← ←len MOV CX,[BP-4] CALL ←Usc CMP BX,0 JLE X1 ; zn = InitializeZone(z, 0x3FF0); MOV BX,03FF0X ; CX ← ←z MOV CX,[BP-2] CALL ←InitializeZone ; ←zn ← BX POP DX PUSH BX ; AddToZone(zn, z+0x7FF0, (len-0x7FF0)>>1); ; BX ← ←zn POP BX PUSH BX PUSH BX ; BX ← ←z MOV BX,[BP-2] ADD BX,07FF0X ; CX ← ←len MOV CX,[BP-4] ADD CX,08010X SHR CX XCHG BX,CX CALL ←AddToZone POP DX ; }; ; else zn = InitializeZone(z, len>>1); JR X2 X1: ; BX ← ←len MOV BX,[BP-4] SHR BX ; CX ← ←z MOV CX,[BP-2] CALL ←InitializeZone ; ←zn ← BX POP DX PUSH BX X2: ; return(zn); ; BX ← ←zn POP BX PUSH BX MOV SP,BP POP BP RET; ; }; ; struct ZN *InitializeZone(z, len) ←InitializeZone: ; struct ZN *z; /* first available address */ ; int len; /* length in words */ PUSH BP MOV BP,SP PUSH CX PUSH BX ; { ; struct SB *firstfree; ; struct ZN *tempznp; ADD SP,0FFFCX ; z->anchor.length = 0; ; BX ← ←z MOV BX,[BP-2] MOV WORD PTR [BX],0 ; z->anchor.pSbPrevious = z->anchor.pSbNext = &z->anchor; ; BX ← ←z MOV BX,[BP-2] ; CX ← ←z MOV CX,[BP-2] XCHG BX,CX ; AX ← ←z MOV AX,[BP-2] MOV [BX+4],AX MOV BX,CX MOV [BX+6],AX ; tempznp = z+1; /* first address after header */ ; BX ← ←z MOV BX,[BP-2] ADD BX,0EX ; ←tempznp ← BX POP DX PUSH BX ; firstfree = (struct SB *) tempznp; ; BX ← ←tempznp POP BX PUSH BX ; ←firstfree ← BX MOV [BP-6],BX ; z->rover = firstfree; ; BX ← ←z MOV BX,[BP-2] ; CX ← ←firstfree MOV CX,[BP-6] MOV [BX+8],CX ; z->minAdr = (int *) firstfree; ; BX ← ←z MOV BX,[BP-2] ; CX ← ←firstfree MOV CX,[BP-6] MOV [BX+10],CX ; z->maxAdr = (int *) firstfree; ; BX ← ←z MOV BX,[BP-2] ; CX ← ←firstfree MOV CX,[BP-6] MOV [BX+12],CX ; AddToZone(z, firstfree, len-(lZn>>1)); ; BX ← ←z MOV BX,[BP-2] PUSH BX ; BX ← ←len MOV BX,[BP-4] ADD BX,0FFF9X ; CX ← ←firstfree MOV CX,[BP-6] CALL ←AddToZone POP DX ; return(z); ; BX ← ←z MOV BX,[BP-2] MOV SP,BP POP BP RET; ; }; ; AddToZone(z, s, len) ←AddToZone: ; struct ZN *z; /* zone itself */ ; struct SB *s; /* first available address */ ; int len; /* available length */ PUSH BP MOV BP,SP PUSH CX PUSH BX ; { ; int lSbFree, *sbLast; ; char *cp; ADD SP,0FFFAX ; len = len << 1; ; BX ← ←len MOV BX,[BP-4] SAL BX ; ←len ← BX MOV [BP-4],BX ; lSbFree = len-lSbOverhead; ; BX ← ←len MOV BX,[BP-4] ADD BX,0FFFCX ; ←lSbFree ← BX MOV [BP-6],BX ; if ((lSbFree < minLSbFree) || (Usc(len, 077774) > 0)) CallSwat(ecAllocate+ 1); ; BX ← ←lSbFree MOV BX,[BP-6] CMP BX,8 JL X5 MOV BX,07FFCX ; CX ← ←len MOV CX,[BP-4] CALL ←Usc CMP BX,0 JLE X4 X5: MOV AL,1 JR X6 X4: XOR AL,AL X6: OR AL,AL JZ X3 MOV BX,01001X CALL ←CallSwat X3: ; cp = (char *) s; ; BX ← ←s MOV BX,[BP-2] ; ←cp ← BX POP DX PUSH BX ; cp = cp+lSbFree; ; BX ← ←lSbFree MOV BX,[BP-6] ; CX ← ←cp POP CX ADD BX,CX ; ←cp ← BX PUSH BX ; sbLast = (int *) cp; /* address of the -1 */ ; BX ← ←cp POP BX PUSH BX ; ←sbLast ← BX MOV [BP-8],BX ; *sbLast = -1; /* last word of free space */ ; BX ← ←sbLast MOV BX,[BP-8] MOV WORD PTR [BX],0FFFFX ; { ; int *min, *max, ti, tib; ADD SP,0FFF8X ; min = z->minAdr; ; BX ← ←z MOV BX,[BP+4] MOV CX,[BX+10] ; ←min ← CX MOV [BP-12],CX ; if (Usc(s, min) < 0) { ; BX ← ←min MOV BX,[BP-12] ; CX ← ←s MOV CX,[BP-2] CALL ←Usc CMP BX,0 JGE X7 ; if (Usc(sbLast, min) >= 0) CallSwat(ecAllocate+2); ; BX ← ←min MOV BX,[BP-12] ; CX ← ←sbLast MOV CX,[BP-8] CALL ←Usc CMP BX,0 JL X8 MOV BX,01002X CALL ←CallSwat X8: ; ti = (int) sbLast; ; BX ← ←sbLast MOV BX,[BP-8] ; ←ti ← BX MOV [BP-16],BX ; tib = (int) min; ; BX ← ←min MOV BX,[BP-12] ; ←tib ← BX POP DX PUSH BX ; ti = ti - tib; ; BX ← ←tib POP BX PUSH BX ; CX ← ←ti MOV CX,[BP-16] SUB CX,BX ; ←ti ← CX MOV [BP-16],CX ; *sbLast = ti; ; BX ← ←sbLast MOV BX,[BP-8] ; CX ← ←ti MOV CX,[BP-16] MOV [BX],CX ; z->minAdr = (int *) s; ; BX ← ←z MOV BX,[BP+4] ; CX ← ←s MOV CX,[BP-2] MOV [BX+10],CX ; }; ; else { JR X9 X7: ; max = z->maxAdr; ; BX ← ←z MOV BX,[BP+4] MOV CX,[BX+12] ; ←max ← CX MOV [BP-14],CX ; if (Usc(s, max) < 0) CallSwat(ecAllocate+3); ; BX ← ←max MOV BX,[BP-14] ; CX ← ←s MOV CX,[BP-2] CALL ←Usc CMP BX,0 JGE X10 MOV BX,01003X CALL ←CallSwat X10: ; ti = (int) max; ; BX ← ←max MOV BX,[BP-14] ; ←ti ← BX MOV [BP-16],BX ; tib = (int) s; ; BX ← ←s MOV BX,[BP-2] ; ←tib ← BX POP DX PUSH BX ; ti = ti - tib; ; BX ← ←tib POP BX PUSH BX ; CX ← ←ti MOV CX,[BP-16] SUB CX,BX ; ←ti ← CX MOV [BP-16],CX ; *max = ti; ; BX ← ←max MOV BX,[BP-14] ; CX ← ←ti MOV CX,[BP-16] MOV [BX],CX ; z->maxAdr = (int *) sbLast; ; BX ← ←z MOV BX,[BP+4] ; CX ← ←sbLast MOV CX,[BP-8] MOV [BX+12],CX ; }; X9: ; }; ADD SP,8 ; s->length = -lSbFree; ; BX ← ←lSbFree MOV BX,[BP-6] NEG BX MOV CX,BX ; BX ← ←s MOV BX,[BP-2] MOV [BX],CX ; Free(z, &s->data); ; BX ← ←s MOV BX,[BP-2] ADD BX,4 ; CX ← ←z MOV CX,[BP+4] CALL ←Free ; }; MOV SP,BP POP BP RET; ; extern int largest ; extern int totAv; ; #asm ;*** illegal symbol name *** ; #asm ←Allocate: ; int *Alloc(z, numWords) ←Alloc: ; struct ZN *z; ; int numWords; PUSH BP MOV BP,SP PUSH CX PUSH BX ; { ; int lSbData, ia, ib, lSb, extra, siz, zeroRqst; ; struct SB *s, *sbRover, *sbOriginalRover, *sbNext; ADD SP,0FFEAX ; largest = totAv = zeroRqst = 0; MOV WORD PTR [BP-18],0 MOV ←totAv,0 MOV ←largest,0 ; if (numWords<0 && numWords>=-2000) { numWords = -numWords; zeroRqst=-1; }; ; BX ← ←numWords MOV BX,[BP-4] CMP BX,0 JGE X12 ; BX ← ←numWords MOV BX,[BP-4] CMP BX,0F830X JL X12 MOV AL,1 JR X13 X12: XOR AL,AL X13: OR AL,AL JZ X11 ; BX ← ←numWords MOV BX,[BP-4] NEG BX ; ←numWords ← BX MOV [BP-4],BX MOV WORD PTR [BP-18],0FFFFX X11: ; lSbData = numWords << 1; ; BX ← ←numWords MOV BX,[BP-4] SAL BX ; ←lSbData ← BX MOV [BP-6],BX ; if (numWords==0) lSbData = 0xFFF0; /* Testing largest avail. */ ; BX ← ←numWords MOV BX,[BP-4] OR BX,BX JNZ X14 MOV WORD PTR [BP-6],0FFF0X X14: ; lSb = UMax(lSbData + lSbOverhead, minLSbFree) ; BX ← ←lSbData MOV BX,[BP-6] ADD BX,4 PUSH BX MOV BX,8 POP CX CALL ←UMax ; ←lSb ← BX MOV [BP-12],BX ; sbOriginalRover = sbRover = z->rover; ; BX ← ←z MOV BX,[BP-2] MOV CX,[BX+8] ; ←sbRover ← CX MOV [BP-22],CX ; ←sbOriginalRover ← CX MOV [BP-24],CX ; for (;;) { X15: ; for (;;) { X17: ; ia = (int) sbRover; ; BX ← ←sbRover MOV BX,[BP-22] ; ←ia ← BX MOV [BP-8],BX ; ia = ia + sbRover->length; ; DI ← ←sbRover MOV DI,[BP-22] MOV BX,[DI] ; CX ← ←ia MOV CX,[BP-8] ADD CX,BX ; ←ia ← CX MOV [BP-8],CX ; sbNext = (struct SB *) ia; ; BX ← ←ia MOV BX,[BP-8] ; ←sbNext ← BX POP DX PUSH BX ; if (sbNext->length <= 0) break; ; DI ← ←sbNext POP DI PUSH DI MOV BX,[DI] CMP BX,0 JG X19 JR X18 X19: ; if (sbNext == sbOriginalRover) sbOriginalRover = sbNext->pSbNext; ; BX ← ←sbOriginalRover MOV BX,[BP-24] ; CX ← ←sbNext POP CX PUSH CX CMP CX,BX JNZ X20 ; BX ← ←sbNext POP BX PUSH BX MOV CX,[BX+4] ; ←sbOriginalRover ← CX MOV [BP-24],CX X20: ; sbNext->pSbNext->pSbPrevious = sbNext->pSbPrevious; ; BX ← ←sbNext POP BX PUSH BX MOV CX,[BX+4] ; BX ← ←sbNext POP BX PUSH BX MOV AX,[BX+6] MOV BX,CX MOV [BX+6],AX ; sbNext->pSbPrevious->pSbNext = sbNext->pSbNext; ; BX ← ←sbNext POP BX PUSH BX MOV CX,[BX+6] ; BX ← ←sbNext POP BX PUSH BX MOV AX,[BX+4] MOV BX,CX MOV [BX+4],AX ; sbRover->length += sbNext->length; ; BX ← ←sbRover MOV BX,[BP-22] ; DI ← ←sbNext POP DI PUSH DI MOV CX,[DI] ADD [BX],CX ; }; JR X17 X18: ; ia = (int) sbNext; ; BX ← ←sbNext POP BX PUSH BX ; ←ia ← BX MOV [BP-8],BX ; ia = ia - lSb; ; BX ← ←lSb MOV BX,[BP-12] ; CX ← ←ia MOV CX,[BP-8] SUB CX,BX ; ←ia ← CX MOV [BP-8],CX ; s = (struct SB *) ia; ; BX ← ←ia MOV BX,[BP-8] ; ←s ← BX MOV [BP-20],BX ; ib = (int) sbRover; ; BX ← ←sbRover MOV BX,[BP-22] ; ←ib ← BX MOV [BP-10],BX ; extra = ia - ib; ; BX ← ←ib MOV BX,[BP-10] ; CX ← ←ia MOV CX,[BP-8] SUB CX,BX ; ←extra ← CX MOV [BP-14],CX ; ia = (int) sbNext; ; BX ← ←sbNext POP BX PUSH BX ; ←ia ← BX MOV [BP-8],BX ; siz = ia - ib; /* (int *) sbNext - (int *) sbRover */ ; BX ← ←ib MOV BX,[BP-10] ; CX ← ←ia MOV CX,[BP-8] SUB CX,BX ; ←siz ← CX MOV [BP-16],CX ; largest = UMax(siz, largest); MOV BX,←largest ; CX ← ←siz MOV CX,[BP-16] CALL ←UMax MOV ←largest,BX ; totAv += siz; ; BX ← ←siz MOV BX,[BP-16] ADD ←totAv,BX ; if ((extra < 0) || (lSb < 0)) { ; BX ← ←extra MOV BX,[BP-14] CMP BX,0 JL X23 ; BX ← ←lSb MOV BX,[BP-12] CMP BX,0 X23: X22: JGE X21 ; sbRover = sbRover->pSbNext; ; BX ← ←sbRover MOV BX,[BP-22] MOV CX,[BX+4] ; ←sbRover ← CX MOV [BP-22],CX ; if (sbRover == sbOriginalRover) break; ; BX ← ←sbOriginalRover MOV BX,[BP-24] ; CX ← ←sbRover MOV CX,[BP-22] CMP CX,BX JNZ X24 JR X16 X24: ; continue; JMP X15 ; }; X21: ; if (extra >= minLSbFree) { ; BX ← ←extra MOV BX,[BP-14] CMP BX,8 JL X25 ; sbRover->length = extra; ; BX ← ←sbRover MOV BX,[BP-22] ; CX ← ←extra MOV CX,[BP-14] MOV [BX],CX ; z->rover = sbRover; ; BX ← ←z MOV BX,[BP-2] ; CX ← ←sbRover MOV CX,[BP-22] MOV [BX+8],CX ; s->length = -lSb; ; BX ← ←lSb MOV BX,[BP-12] NEG BX MOV CX,BX ; BX ← ←s MOV BX,[BP-20] MOV [BX],CX ; }; ; else { JR X26 X25: ; sbRover->pSbNext->pSbPrevious = sbRover->pSbPrevious; ; BX ← ←sbRover MOV BX,[BP-22] MOV CX,[BX+4] ; BX ← ←sbRover MOV BX,[BP-22] MOV AX,[BX+6] MOV BX,CX MOV [BX+6],AX ; sbRover->pSbPrevious->pSbNext = sbRover->pSbNext; ; BX ← ←sbRover MOV BX,[BP-22] MOV CX,[BX+6] ; BX ← ←sbRover MOV BX,[BP-22] MOV AX,[BX+4] MOV BX,CX MOV [BX+4],AX ; z->rover = sbRover->pSbNext; ; BX ← ←z MOV BX,[BP-2] ; CX ← ←sbRover MOV CX,[BP-22] MOV DI,CX MOV CX,[DI+4] MOV [BX+8],CX ; s = sbRover; ; BX ← ←sbRover MOV BX,[BP-22] ; ←s ← BX MOV [BP-20],BX ; s->length = (-s->length); ; DI ← ←s MOV DI,[BP-20] MOV BX,[DI] NEG BX MOV CX,BX ; BX ← ←s MOV BX,[BP-20] MOV [BX],CX ; }; X26: ; s->user = ReturnLoc(MyFrame()); /* survey of callers of Alloc */ ; BX ← ←s MOV BX,[BP-20] JR $+5 X16: JMP X27 PUSH BX CALL ←MyFrame CALL ←ReturnLoc MOV CX,BX POP BX MOV [BX+2],CX ; ia = ((int) s) + offsetSbData; ; BX ← ←s MOV BX,[BP-20] ADD BX,4 ; ←ia ← BX MOV [BP-8],BX ; Zero(ia, numWords); ; BX ← ←numWords MOV BX,[BP-4] ; CX ← ←ia MOV CX,[BP-8] CALL ←Zero ; return (ia); ; BX ← ←ia MOV BX,[BP-8] MOV SP,BP POP BP RET; ; }; /* didn't work: while (sbRover != sbOriginalRover); */ X27: ; z->rover = sbRover; ; BX ← ←z MOV BX,[BP-2] ; CX ← ←sbRover MOV CX,[BP-22] MOV [BX+8],CX ; if (numWords!=0) CallSwat(ecAllocate+5); ; BX ← ←numWords MOV BX,[BP-4] OR BX,BX JZ X28 MOV BX,01005X CALL ←CallSwat X28: ; return 0; XOR BX,BX MOV SP,BP POP BP RET; ; }; ; Free(z, s) ←Free: ; struct ZN *z; ; int *s; PUSH BP MOV BP,SP PUSH CX PUSH BX ; { ; struct SB *sbp, *sbAnchor, *sbT; ; int ia; ; if (s==0) return; /* God damn it! */ ADD SP,0FFF8X ; BX ← ←s MOV BX,[BP-4] OR BX,BX JNZ X29 MOV SP,BP POP BP RET; X29: ; ia = (int) s; ; BX ← ←s MOV BX,[BP-4] ; ←ia ← BX POP DX PUSH BX ; ia = ia-offsetSbData; ; BX ← ←ia POP BX ADD BX,0FFFCX ; ←ia ← BX PUSH BX ; sbp = (struct SB *) ia; ; BX ← ←ia POP BX PUSH BX ; ←sbp ← BX MOV [BP-6],BX ; if (sbp->length >= 0) CallSwat(ecAllocate+6); ; DI ← ←sbp MOV DI,[BP-6] MOV BX,[DI] CMP BX,0 JL X30 MOV BX,01006X CALL ←CallSwat X30: ; sbAnchor = &z->anchor; ; BX ← ←z MOV BX,[BP-2] ; ←sbAnchor ← BX MOV [BP-8],BX ; CheckZone(z, 0); XOR BX,BX ; CX ← ←z MOV CX,[BP-2] CALL ←CheckZone ; sbp->length = -sbp->length; ; DI ← ←sbp MOV DI,[BP-6] MOV BX,[DI] NEG BX MOV CX,BX ; BX ← ←sbp MOV BX,[BP-6] MOV [BX],CX ; CheckBounds(z, sbp); ; BX ← ←sbp MOV BX,[BP-6] ; CX ← ←z MOV CX,[BP-2] CALL ←CheckBounds ; CheckFreeNode(z, sbAnchor); ; BX ← ←sbAnchor MOV BX,[BP-8] ; CX ← ←z MOV CX,[BP-2] CALL ←CheckFreeNode ; sbT = sbAnchor->pSbNext; ; BX ← ←sbAnchor MOV BX,[BP-8] MOV CX,[BX+4] ; ←sbT ← CX MOV [BP-10],CX ; sbp->pSbPrevious = sbAnchor; ; BX ← ←sbp MOV BX,[BP-6] ; CX ← ←sbAnchor MOV CX,[BP-8] MOV [BX+6],CX ; sbp->pSbNext = sbT; ; BX ← ←sbp MOV BX,[BP-6] ; CX ← ←sbT MOV CX,[BP-10] MOV [BX+4],CX ; sbAnchor->pSbNext = sbp; ; BX ← ←sbAnchor MOV BX,[BP-8] ; CX ← ←sbp MOV CX,[BP-6] MOV [BX+4],CX ; sbT->pSbPrevious = sbp; ; BX ← ←sbT MOV BX,[BP-10] ; CX ← ←sbp MOV CX,[BP-6] MOV [BX+6],CX ; }; MOV SP,BP POP BP RET; ; CheckZone(z, p) ←CheckZone: ; struct ZN *z; ; int p; PUSH BP MOV BP,SP PUSH CX PUSH BX ; { ; int freecount, addit, ia, cnt; ; struct SB *s, *sbAnchor; ; if (*z->maxAdr != -1) CallSwat(ecAllocate+7); ADD SP,0FFF4X ; BX ← ←z MOV BX,[BP-2] MOV CX,[BX+12] MOV DI,CX MOV BX,[DI] CMP BX,0FFFFX JZ X31 MOV BX,01007X CALL ←CallSwat X31: ; freecount = 0; MOV WORD PTR [BP-6],0 ; ia = (int) z->minAdr; ; BX ← ←z MOV BX,[BP-2] MOV CX,[BX+10] ; ←ia ← CX MOV [BP-10],CX ; s = (struct SB *) ia; ; BX ← ←ia MOV BX,[BP-10] ; ←s ← BX MOV [BP-14],BX ; for (;;) { X32: ; if (Usc(z->maxAdr, s) <= 0) break; ; BX ← ←z MOV BX,[BP-2] MOV CX,[BX+12] ; BX ← ←s MOV BX,[BP-14] CALL ←Usc CMP BX,0 JG X34 JR X33 X34: ; addit = s->length; ; DI ← ←s MOV DI,[BP-14] MOV BX,[DI] ; ←addit ← BX MOV [BP-8],BX ; if (addit >= 0) { ; BX ← ←addit MOV BX,[BP-8] CMP BX,0 JL X35 ; CheckFreeNode(z, s); ; BX ← ←s MOV BX,[BP-14] ; CX ← ←z MOV CX,[BP-2] CALL ←CheckFreeNode ; freecount += 1; INC WORD PTR [BP-6] ; }; ; else { JR X36 X35: ; addit = (-addit); ; BX ← ←addit MOV BX,[BP-8] NEG BX ; ←addit ← BX MOV [BP-8],BX ; }; X36: ; ia = ia+addit; ; BX ← ←addit MOV BX,[BP-8] ; CX ← ←ia MOV CX,[BP-10] ADD CX,BX ; ←ia ← CX MOV [BP-10],CX ; if (Usc(ia, s) <= 0) CallSwat(ecAllocate+8); ; BX ← ←s MOV BX,[BP-14] ; CX ← ←ia MOV CX,[BP-10] CALL ←Usc CMP BX,0 JG X37 MOV BX,01008X CALL ←CallSwat X37: ; s = (struct SB *) ia; ; BX ← ←ia MOV BX,[BP-10] ; ←s ← BX MOV [BP-14],BX ; }; JR X32 X33: ; if (((int *) s) != z->maxAdr) CallSwat(ecAllocate+9); ; BX ← ←z MOV BX,[BP-2] MOV CX,[BX+12] ; BX ← ←s MOV BX,[BP-14] CMP BX,CX JZ X38 MOV BX,01009X CALL ←CallSwat X38: ; cnt = -22000; MOV WORD PTR [BP-12],0AA10X ; sbAnchor = &z->anchor; ; BX ← ←z MOV BX,[BP-2] ; ←sbAnchor ← BX POP DX PUSH BX ; s = sbAnchor->pSbNext; ; BX ← ←sbAnchor POP BX PUSH BX MOV CX,[BX+4] ; ←s ← CX MOV [BP-14],CX ; for (;;) { X39: ; if (s == sbAnchor) break; ; BX ← ←sbAnchor POP BX PUSH BX ; CX ← ←s MOV CX,[BP-14] CMP CX,BX JNZ X41 JR X40 X41: ; CheckFreeNode(z, s); ; BX ← ←s MOV BX,[BP-14] ; CX ← ←z MOV CX,[BP-2] CALL ←CheckFreeNode ; freecount -= 1; DEC WORD PTR [BP-6] ; cnt -= 1; DEC WORD PTR [BP-12] ; if (cnt == 0) CallSwat(ecAllocate+10); ; BX ← ←cnt MOV BX,[BP-12] OR BX,BX JNZ X42 MOV BX,0100AX CALL ←CallSwat X42: ; s = s->pSbNext; ; BX ← ←s MOV BX,[BP-14] MOV CX,[BX+4] ; ←s ← CX MOV [BP-14],CX ; }; JR X39 X40: ; if (freecount != 0) CallSwat(ecAllocate+11); ; BX ← ←freecount MOV BX,[BP-6] OR BX,BX JZ X43 MOV BX,0100BX CALL ←CallSwat X43: ; }; MOV SP,BP POP BP RET; ; CheckFreeNode(z, s) ←CheckFreeNode: ; struct ZN *z; ; struct SB *s; PUSH BP MOV BP,SP PUSH CX PUSH BX ; { ; CheckBounds(z, s); ; BX ← ←s POP BX PUSH BX ; CX ← ←z MOV CX,[BP-2] CALL ←CheckBounds ; CheckBounds(z, s->pSbNext); ; BX ← ←s POP BX PUSH BX MOV CX,[BX+4] MOV BX,CX ; CX ← ←z MOV CX,[BP-2] CALL ←CheckBounds ; CheckBounds(z, s->pSbPrevious); ; BX ← ←s POP BX PUSH BX MOV CX,[BX+6] MOV BX,CX ; CX ← ←z MOV CX,[BP-2] CALL ←CheckBounds ; if ((s != &z->anchor) && (s->length < minLSbFree)) CallSwat(ecAllocate+12); ; BX ← ←z MOV BX,[BP-2] ; CX ← ←s POP CX PUSH CX CMP CX,BX JZ X45 ; DI ← ←s POP DI PUSH DI MOV BX,[DI] CMP BX,8 JGE X45 MOV AL,1 JR X46 X45: XOR AL,AL X46: OR AL,AL JZ X44 MOV BX,0100CX CALL ←CallSwat X44: ; if (s->pSbNext->pSbPrevious != s) CallSwat(ecAllocate+13); ; BX ← ←s POP BX PUSH BX MOV CX,[BX+4] MOV DI,CX MOV BX,[DI+6] ; CX ← ←s POP CX PUSH CX CMP BX,CX JZ X47 MOV BX,0100DX CALL ←CallSwat X47: ; }; MOV SP,BP POP BP RET; ; CheckBounds(z, s) ←CheckBounds: ; struct ZN *z; ; struct SB *s; PUSH BP MOV BP,SP PUSH CX PUSH BX ; { ; int tip; ; if (s != &z->anchor) { PUSH DX ; BX ← ←z MOV BX,[BP-2] ; CX ← ←s MOV CX,[BP-4] CMP CX,BX JZ X48 ; tip = (int) s; ; BX ← ←s MOV BX,[BP-4] ; ←tip ← BX POP DX PUSH BX ; if ((Usc(tip+s->length, z->maxAdr) > 0) || (Usc(s, z->minAdr) < 0)) CallSwat(ecAllocate+14); ; DI ← ←s MOV DI,[BP-4] MOV BX,[DI] ; CX ← ←tip POP CX PUSH CX ADD CX,BX ; BX ← ←z MOV BX,[BP-2] MOV AX,[BX+12] MOV BX,AX CALL ←Usc CMP BX,0 JG X51 ; BX ← ←z MOV BX,[BP-2] MOV CX,[BX+10] MOV BX,CX ; CX ← ←s MOV CX,[BP-4] CALL ←Usc CMP BX,0 JGE X50 X51: MOV AL,1 JR X52 X50: XOR AL,AL X52: OR AL,AL JZ X49 MOV BX,0100EX CALL ←CallSwat X49: ; }; X48: ; }; MOV SP,BP POP BP RET; ; #asm PUBLIC ←Allocate ; Externals Declared Here PUBLIC ←GetAll PUBLIC ←InitializeZone PUBLIC ←AddToZone PUBLIC ←Free PUBLIC ←Alloc PUBLIC ←CheckZone PUBLIC ←CheckBounds PUBLIC ←CheckFreeNode C←CODE ENDS ; Number of Bytes of Code = 061EX, (1566)