STACK EQU 1FH BOTTOM EQU 00H TOP DATA 3EH OUT EQU 20H IN EQU 30H N EQU 8 M EQU 30 K DATA 3FH TST: MOV SP,#5FH LCALL SETNULL MOV DPH,#OUT MOV DPL,#0 MOV R2,#0 CLR A CLROUT: MOVX @DPTR,A INC DPTR DJNZ R2,CLROUT MOV R0,#IN MOV R2,#N+1 CLRIN: MOV @R0,A INC R0 DJNZ R2,CLRIN MOV K,#0 MOV A,#0 LCALL DPUSH MOV A,#M LCALL DPUSH LCALL BEIBAO STOP: LJMP STOP WLIST: DB 1,9,12 DB 6,3,20 DB 15,5 BEIBAO: LCALL DPOP MOV R2,A LCALL DPOP MOV R3,A MOV DPTR,#WLIST MOVC A,@A+DPTR MOV R4,A CLR C SUBB A,R2 JNZ BB1 MOV A,R3 ADD A,#IN MOV R0,A MOV A,R4 MOV @R0,A MOV DPH,#OUT MOV A,K MOV B,#N MUL AB MOV DPL,A MOV R0,#IN MOV A,R3 INC A MOV R7,A SAVE: MOV A,@R0 JZ SAVE1 MOVX @DPTR,A INC DPTR SAVE1: INC R0 DJNZ R7,SAVE INC K BB1: MOV A,R3 INC A XRL A,#N JZ BBE JNC BB2 MOV A,R2 LCALL DPUSH MOV A,R3 LCALL DPUSH MOV A,R3 ADD A,#IN MOV R0,A MOV A,R4 MOV @R0,A MOV A,R3 INC A LCALL DPUSH MOV A,R2 CLR C SUBB A,R4 LCALL DPUSH LCALL BEIBAO LCALL DPOP MOV R3,A LCALL DPOP MOV R2,A BB2: MOV A,R3 ADD A,#IN MOV R0,A MOV A,#0 MOV @R0,A MOV A,R3 INC A LCALL DPUSH MOV A,R2 LCALL DPUSH LCALL BEIBAO BBE: RET SETNULL: MOV A,#BOTTOM MOV TOP,A RET DPUSH: INC TOP MOV DPH,#STACK MOV DPL,TOP MOVX @DPTR,A RET DPOP: MOV DPH,#STACK MOV DPL,TOP MOVX A,@DPTR DEC TOP RET END