CODEKTVXLNCHH

;KIEM TRA 10 SO TRONG BANG TAB,SO NAO LA SO HOAN HAO THI LUU VAO VI TRI NHO 20H-29H

;KO LA SO HOAN HAO THI LUU VAO VI TRI NHO 30H-39H

ORG     0000H

LJMP    START

;---------------------------------

ORG     03H                   ;external interrupt 0

RETI

ORG     0BH                   ;timer 0 interrupt

RETI

ORG     13H                   ;external interrupt 1

RETI

ORG     1BH                   ;timer 1 interrupt

RETI

ORG     23H                   ;serial port interrupt

RETI

;=====================================

KHOI_TAO:                       ;set up control registers

     MOV   TCON,#00H

     MOV   TMOD,#00H

     MOV   PSW,#00H            

     MOV   IE,#00H               ;disable interrupts

RET

;-------------------------------------

;HAM MAIN

;-------------------------------------

;ORG      30H

START:  ACALL   KHOI_TAO        ;KHOI TAO CAC THANH GHI

        MOV     A,#0           ;CHI SO BANG TAB

        MOV     R5,#0           ;R5 DEM SO UOC CUA N

        MOV     R0,#20H          ;R6 LUU DIA CHI VUNG NHO CUA NHUNG SO HOAN HAO

        MOV     R1,#30H          ;R7 LUU DIA CHI VUNG NHO CUA NHUNG SO KHONG PHAI SO HOAN HAO

        MOV     R7,#10       

        MOV     DPTR,#TAB

KIEMTRA:

        MOVC    A,@A+DPTR

        MOV     R2,#2

        ;LAY N/2 DE TIM UOC CUA N

        MOV     B,#2      

        MOV     2FH,A               ;LUU LAI N TRONG DIA CHI 2FH    

        DIV     AB     

        MOV     R4,A               ; R4= N/2

;TIM CAC UOC CUA N LUU VAO STACH

L1:

        MOV     A,2FH               ;NAP LAI N VAO A

        MOV     B,R2

        DIV     AB

        MOV     R3,B

        CJNE    R3,#0,LOAI

        MOV     B,R2      

        PUSH    B

        INC     R5

LOAI:

        INC     R2

        DJNZ    R4,L1

;CONG CAC UOC VA SO SANH

        MOV     A,#0

L2:

        MOV     B,#0    ;DUNG B DE LAY LAI CAC UOC CUA N TU STACK

        POP     B

        ADD     A,B

        DJNZ    R5,L2

;SO SANH TONG CAC UOC VOI SO BAN DAU     

        CJNE    A,2FH,NO

;NHAN SO HOAN HAO VA NAP VAO 20H

        ;MOV     A,R3

        MOV     @R0,2FH

        INC     R0

        LJMP    TIEPTUC

;KHONG PHAI SO HOAN HAO

NO:

        ;MOV     A,R3

        MOV     @R1,2FH

        INC     R1

TIEPTUC:

        MOV     A,#0

        INC     A

        DJNZ    R7,KIEMTRA

 TAB:     DB 6,8,12,24,16,4,5,7,9,10

RET

END

Bạn đang đọc truyện trên: AzTruyen.Top

Tags: