www.xdanger.com Thinking up makes looking up ...

MCS-51(8086)的一个汇编

  到昨天为止,用了一个星期写了一个汇编程序,是这个学期课程设计的作业。这大概是我接触到的最长的一个汇编了吧,感觉真BT。

  目的很简单,就是有八个按钮,分别控制千、百、十、个位的+-(比如按百位的+数字就加100),带进位,在4个7晶体管上显示相应的4位数字,初始值为0000。



ORG 8000H
               LJMP MAIN
ORG 8003H
               LJMP PKEYI
ORG         8100H
MAIN:       MOV R1,#7BH
               MOV R6,#4H
START:     MOV @R1,#0
               DEC R1
               DJNZ R6,START
               LCALL INI79
               LCALL RDIR
PROGN:     JNB 00H,PROGN
               CLR 00H
               MOV R0,#40H
               MOV A,@R0
               CJNEA,#00,NEXT1
               LCALL PROGN0
NEXT1:     CJNE A,#02,NEXT2
               LCALL PROGN1
NEXT2:     CJNE A,#03,NEXT3
               LCALL PROGN2
NEXT3:     CJNE A,#04,NEXT4
               LCALL PROGN3
NEXT4:     CJNE A,#05,NEXT5
               LCALL PROGN4
NEXT5:     CJNE A,#06,NEXT6
               LCALL PROGN5
NEXT6:     CJNE A,#07,NEXT7
               LCALL PROGN6
NEXT7:     CJNE A,#08,PROGN
               LCALL PROGN7
               LCALL 8900H
               LJMP PROGN
ORG 8400H
PROGN0:   MOV R1,#7BH
               MOV A,@R1
               CJNE A,#9H,ADD0
               MOV @R1,#00H
               LJMP EXIT0
ADD0:       INC @R1
EXIT0:      LCALL 8900H
               RET
ORG 8450H
PROGN1:    MOV R1,#7BH
               MOV A,@R1
               CJNE A,#0H,SUB0
               LJMP EXIT1
SUB0:       DEC @R1
EXIT1:      LCALL 8900H
               RET
ORG 8500H
PROGN2:   MOV R1,#7AH
               MOV A,@R1
               CJNE A,#9H,ADD1
               MOV @R1,#0H
               LCALL PROGN0
               LJMP EXIT2
ADD1:       INC @R1
EXIT2:      LCALL 8900H
               RET
ORG 8550H
PROGN3:   MOV R1,#7AH
               MOV A,@R1
               CJNE A,#0H,SUB1
               MOV @R1,#9H
               LCALL PROGN1
               LJMP EXIT3
SUB1:       DEC @R1
EXIT3:      LCALL 8900H
               RET
ORG 8600H
PROGN4:   MOV R1,#79H
               MOV A,@R1
               CJNE A,#9H,ADD2
               MOV @R1,#0H
               LCALL PROGN2
               LJMP EXIT4
ADD2:       INC @R1
EXIT4:      LCALL 8900H
                 RET
ORG 8650H
PROGN5:   MOV R1,#79H
               MOV A,@R1
               CJNE A,#9H,SUB2
               MOV @R1,#9H
               LCALL PROGN3
               LJMP EXIT5
SUB2:       DEC @R1
EXIT5:      LCALL 8900H
               RET
ORG 8700H
PROGN6:   MOV R1,#78H
               MOV A,@R1
               CJNE A,#9H,ADD3
               MOV @R1,#0H
               LCALL PROGN4
               LJMP EXIT6
ADD3:       INC @R1
EXIT6:      LCALL 8900H
               RET
ORG 8750H
PROGN7:   MOV R1,#78H
               MOV A,@R1
               CJNE A,#0H,SUB3
               MOV @R1,#9H
               LCALL PROGN5
               LJMP EXIT7
SUB3:       DEC @R1
EXIT7:      LCALL 8900H
               RET
ORG 8800H
INI79:       MOV DPTR,#0DFFFH
               MOV A,#0DCH
               MOVX @DPTR,A
WNDU:      MOVX A,@DPTR
               JB ACC.7,WNDU
               MOV A,#0
               MOVX @DPTR,A
               MOV A,#34
               MOVX @DPTR,A
               MOV IE,#81H
               RET
ORG 8900H
RDIR:        MOV DPTR,#0DFFFH
               MOV A, #90H
               MOVX @DPTR,A
               MOV R0,#7BH
               MOV R7,#4
               MOV DPTR,#0DEFFH
RDL0:        MOV A,@R0
               ADD A,#6
               MOVC A,@A+PC
               CPL A
               MOVX @DPTR,A
               DEC R0
               DJNZ R7,RDL0
               RET
SEG:         DB 3FH,6,5BH,4FH,
               DB 66H,6DH,
               DB 7DH,7,7FH,6FH,
               DB 77H,7CH
               DB 39H,5EH,79H,71H,
               DB 73H,3EH,
               DB 31H,6FH,1CH,23H,40H,3,
               DB 18H,38H,0
ORG 8A00H
PKEYI:      PUSH PSW
               PUSH DPL
               PUSH DPH
               PUSH ACC
               PUSH B
               SETB PSW.3
               MOV DPTR,#0DFFFH
               MOVX A,@DPTR
               ANL A,#0FH
               JZ PKYR
               MOV A,#40H
               MOVX @DPTR,A
               MOV DPTR,#0DEFFH
               MOVX A,@DPTR
               MOV R2,A
               ANL A,#18H
               RR A
               RR A
               RR A
               MOV B,#2
               MUL AB
               XCH A,R2
               ANL A,#3
               ADD A,R2
               MOV R0,#40H
               MOV @R0,A
               SETB 0
PKYR:        POP B
               POP ACC
               POP DPH
               POP DHL
               POP PSW
               RET1

This site is licensed under a Creative Commons License .