ORG 2D00H ;SET ORIGIN BEGIN: LXI SP,STACK+8 ;INTIALIZE STACK LHLD SBOT ;BOTTOM OF SOURCE XCHG ;D,E=SBOT=(B) LHLD SSTRT ;H,L=SSTRT=(A) MOV C,L MOV B,H ;SAVE IN B,C CALL COMPH ;COMPLIMENT(A) & ADD 1 DAD D ;H,L=(B)-(A)=BLOCKSIZE PUSH H ;SAVE ON STACK LHLD DTOP ;TOP OF DESTINATION XCHG ;D,E=DTOP=(C) MOV L,C MOV H,B ;H,L=SSTRT CALL COMPH DAD D ;H,L=(C)-(A)=DISPL SHLD DISPL ;SAVE DISPLACEMENT PUSH PSW ;HAS SIGN OF DISPL LDA FUNC ;CHECK FOR MOVE ORA A JZ STEP2 ;IF 0 FIX REF. ONLY POP PSW JC DOWN ;(C)>(A) IF CARRY SET ;IF COME HERE DESTINATION IS ABOVE SOURCE ;SO MOVE IS DONE HEAD-TO-HEAD UP: XCHG ;H,L=D,E=DTOP POP D ;D,E=BLKSIZE X: LDAX B ;B,C=SSTRT=SOURCE PTR. MOV M,A ;MOVE TO NEW LOC. MOV A,D ORA A JNZ Y ;CHECK IF THRU MOV A,E ORA A JZ TEST ;IF D,E=0 THEN MOVE DONE Y: INX H ;INCR DEST. PTR. TO NEXT INX B ;INCR SOURCE PTR. DCX D ;COUNT DOWN BLKSIZE JMP X ;CONTINUE ;IF COME HERE DESTINATION IS BELOW SOURCE ;SO MOVE IS DONE TAIL-TO-TAIL DOWN: XCHG ;H,L=D,E=DTOP POP D ;D,E=BLKSIZE PUSH D ;SAVE ON STACK DAD D ;H,L=DBOT=DTOP+BLKSIZE XCHG ;D,E=DBOT:H,L=BLKSIZE DAD B ;H,L=SSTRT+BLKSIZE=SBOT XCHG ;D,E=SBOT:H,L=DBOT POP B ;B,C=BLKSIZE XX: LDAX D ;D,E=SOURCE PTR. MOV M,A ;MOVE TO NEW LOC. MOV A,B ORA A JNZ YY ;CHECK IF THRU MOV A,C ORA A JZ TEST ;B,C=0,MOVE DONE YY: DCX H ;PT. TO NEXT DEST. DCX D ;PT. TO NEXT SOURCE DCX B ;COUNT DOWN BLKSIZE JMP XX ;CONTINUE TEST: LDA FUNC ;=02 IF MOVE ONLY CPI 02H JZ DONE ;COME HERE TO DO REFERENCE FIXING. ;NECESSARY ONLY FOR 3 BYTE OP CODES STEP2: LXI B,TABL3 ;B,C= TABLE PTR LHLD SBOT ;NEED TO ADD 1 TO SBOT INX H SHLD SBOT LHLD START ;D,E=MEMORY PTR. XCHG CHEKF: LHLD SSTP ;CHECK FOR END OF FILE CALL COMPH ;D,E-MEM. PTR. DAD D ;D,E-H,L=DIFF. JC DONE ;DIFF.>=0,CARRY SET NEXT: LDAX D ;LOAD MEM. USING D,E MOV H,A ;SAVE IN H XRA A ;ZERO ACCUM. MOV L,A ;SET UP CNTR. COMP3: INR L ;BUMP CNTR MOV A,L CPI 27D ;CHECK FOR END OF TABLE JZ AGAIN ;IF THRU..LOOK @ 2 BYT OPS LDAX B ;LOAD TABLE ENTRY SUB H ;COMP. WITH CURR. MEM. JZ MTCH3 ;JMP IF MATCH INX B ;ELSE BUMP TABLE PTR. JMP COMP3 ;LOOK AGAIN AGAIN: LXI B,TABL2 ;NOW,LOOK AT 2 BYTE OPS XRA A ;ZERO ACCUM. MOV L,A ;SET CTR. COMP2: INR L ;BUMP CTR. MOV A,L CPI 19D ;CHECK FOR END TABLE JZ OUT1 ;NO MATCH 2 OR 3 BYTE OPS LDAX B ;LOAD TABLE ENTRY SUB H ;COMP. WITH CURRENT MEM. JZ OUT2 ;JMP IF MATCH INX B ;ELSE BUMP TABLE PTR. JMP COMP2 ;LOOK AGAIN MTCH3: LHLD SBOT ;FOUND 3 BYTE OP CODE CALL COMPH ;IS ADDR. IN RANGE? INX D ;GET LO ADDR. BYTE LDAX D ;LOAD IN ACC. MOV C,A ;STORE IN C INX D ;GET HI ADDR. BYTE LDAX D ;LOAD ACC. MOV B,A ;PUT IN B DAD B ;H,L=MEM.ADDR.-SBOT JC OUT1 ;MEM.ADDR.>=SBOT+1,C SET LHLD SSTRT ;LESS THAM (A)? CALL COMPH DAD B ;H,L=MEM.ADDR.-SSTRT JNC OUT1 ;MEM.ADDR. < SSTRT,C=0 FIXR: LHLD DISPL ;IF COME HERE,IN RANGE. DAD B ;H,L=MEM.ADDR.+DISPL MOV A,H STAX D ;STORE NEW HI ADDR. DCX D ;PT. AT LO ADDR. BYTE MOV A,L STAX D ;STORE NEW LO ADDR. BYTE OUT2: INX D OUT1: INX D ;ADV. PTR. TO NEXT OP LXI B,TABL3 ;RESET TABLE PTR. JMP CHEKF ;CONTINUE DONE: RST 07 ;FINIS,RETURN TO DDT ;***** SUBROUTINE ***** COMPH: MOV A,H ;SUBROUTINE USED TO CMA ;FIND 2'S COMPLIMENT MOV H,A ;REPRESENTATION OF MOV A,L ;H,L REGISTER PAIR CMA MOV L,A INX H RET ;***** TABLES AND CONSTANTS ***** TABL2: DB 06H,0EH,16H ;TABLE OF 2 BYTE DB 1EH,26H,2EH ;OP CODES DB 36H,3EH,0C6H DB 0CEH,0DEH,0D6H DB 0DBH,0DEH,0E6H DB 0EEH,0F6H,0FEH TABL3: DB 01H,11H,21H ;TABLE OF 3 BYTE DB 22H,2AH,31H ;OP CODES DB 32H,3AH,0C2H DB 0C3H,0C4H,0CAH DB 0CCH,0CDH,0D2H DB 0D4H,0DAH,0DCH DB 0E2H,0E4H,0EAH DB 0ECH,0F2H,0F4H DB 0FAH,0FCH SSTRT: DS 02H ;SOURCE TOP(A) SBOT: DS 02H ;SOURCE BOTTOM(B) DTOP: DS 02H ;DESTINATION TOP(C) START: DS 02H ;START OF REF. FIXING(D) SSTP: DS 02H ;END OF REF. FIXING(E) FUNC: DS 01H ;00=REF. FIX ONLY (F) ;02=MOVE ONLY ;01=MOVE & FIX DISPL: DS 02H ;DISPLACEMENT STACK: DS 08H ;MEM. SPACE FOR STACK