STACK EQU 1FH
BOTTOM EQU 00H
TOP DATA 3EH
TREE EQU 20H
POINT EQU 21H
OUT EQU 22H
TST:
MOV SP,#5FH
MOV DPTR,#DATS
MOV P2,#TREE
MOV R0,#0
MOV R2,#19
CPY:
CLR A
MOVC A,@A+DPTR
MOVX @R0,A
INC DPTR
INC R0
DJNZ R2,CPY
MOV DPTR,#FDAT
MOV P2,#POINT
MOV R0,#0
MOV R2,#19
CPY1:
CLR A
MOVC A,@A+DPTR
MOVX @R0,A
INC DPTR
INC R0
DJNZ R2,CPY1
MOV DPH,#OUT
MOV DPL,#0
MOV R2,#0
CLR A
CLEAR:
MOVX @DPTR,A
INC DPTR
DJNZ R2,CLEAR
MOV P2,#TREE
MOV R0,#0
MOV DPH,#OUT
MOV DPL,#0
MOVX A,@R0
MOVX @DPTR,A
MOV R2,A
INC R2
INC R0
INC DPTR
JZ STOP
MOV SP,#5FH
LCALL SETNULL
LCALL PRE
STOP: LJMP STOP
DATS:
DB 12H,41H,42H,43H
DB 44H,45H,46H,47H
DB 48H,49H,4AH,4BH
DB 4CH,4DH,4EH,4FH
DB 50H,51H,52H
FDAT:
DB 00H,00H,01H,01H
DB 01H,02H,02H,04H
DB 05H,05H,07H,07H
DB 08H,08H,08H,0AH
DB 0AH,0AH,0BH
PRE:
MOV P2,#TREE
MOVX A,@R0
JZ PREND
MOVX @DPTR,A
INC DPTR
MOV A,R0
INC A
MOV R1,A
LOOP:
MOV A,R1
XRL A,R2
JZ PREND
MOV P2,#POINT
MOVX A,@R1
CLR C
SUBB A,R0
JC LOOPE
JNZ PREND
MOV A,R0
LCALL DPUSH
MOV A,R1
LCALL DPUSH
MOV R0,A
LCALL PRE
LCALL DPOP
MOV R1,A
LCALL DPOP
MOV R0,A
LOOPE:
INC R1
SJMP LOOP
PREND:
RET
SETNULL:
MOV A,#BOTTOM
MOV TOP,A
RET
DPUSH:
INC TOP
PUSH DPH
PUSH DPL
MOV DPH,#STACK
MOV DPL,TOP
MOVX @DPTR,A
POP DPL
POP DPH
RET ;结束。
DPOP:
PUSH DPH
PUSH DPL
MOV DPH,#STACK
MOV DPL,TOP
MOVX A,@DPTR
DEC TOP
POP DPL
POP DPH
RET