⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 chap2.asm

📁 摩托罗拉Mc6805利程
💻 ASM
字号:
; Chapter 2 6805 assembly language programs; Jonathan W. Valvano; This software accompanies the book,; Real Time Embedded Systems published by Brooks Cole;; Program 2.1. Memory allocation places variables in RAM and programs in ROM.; MC68HC05J1A      org $00C0 ;RAMcnt   rmb 1     ;global      org $0300 ;ROMconst fcb 5  ;amount to addinit  lda #$FF      sta DDRA ;outputs      clr cnt        rtsmain  rsp     ;sp=>RAM      bsr initloop  lda cnt      sta PORTA ;output      add const      sta cnt      bra loop      org $07FE ;ROM      fdb main ;reset vector; Program 2.8: An assembly subroutine that uses ; comments to delineate its beginning and end.;***************Abs*************************; Input: RegA is signed 8 bit; Output: Reg A is absolute value 0 to 127Abs: tsta     ; already positive?     bpl  ok     negaok   rts* ------------end of Abs -----------------; Program 2.9: Sometimes we can remove a conditional branch and simplify the program.; 6805/6808; uses conditional branchadd16a lda  u1+1  ;lsb       add  u2+1       sta  u3+1       lda  u1    ;msb       bcc  noc       inca       ;carrynoc    add  u2       sta  u3       rts; no conditional branchadd16b lda  u1+1  ;lsb       add  u2+1       sta  u3+1       lda  u1    ;msb       adc  u2       sta  u3       rts; Program 2.11: Assembly implementation of SCI initialization.; MC68HC05C8init lda #$33  ;1200 baud     sta BAUD     lda #$00  ;mode     sta SCCR1     lda #$0C  ;tie=rie=0,      sta SCCR2 ;te=re=1     rts; Program 2.12: Assembly implementation of SCI input.; MC68HC05C8; Return RegA = characterInChar brclr 5,SCSR,InChar       lda SCDR   ;SCI data       rts; Program 2.13: Assembly implementation of SCI output.; MC68HC05C8; RegA is data to outputOutChar brclr 7,SCSR,OutChar           sta SCDR ;output        rts; Program 2.15: Assembly implementation of input decimal number.; MC68HC05C8 or MC68HC708XL36; Input a byte from the SCI ; Inputs:  none; Outputs: Reg X 0 to 255;          C=1 if errorDIGIT   rmb 1      ;globalInUDec  clrx       ;N=0         InUDloop bsr InChar ;Next input        bsr OutChar ;Echo        cmp #13    ;done if cr        beq InUDret ;with C=0        cmp #'0        blo InUDerr ;error?        cmp #'9        bhi InUDerr ;error?        and #$0F    ;0-9 digit        sta DIGIT        lda #10        mul        tstx        ;overflow?        bne InUDerr         add DIGIT ;N=10*N+DIGIT        tax        bra  InUDloop InUDerr ldaa #'?        bsr  OutChar        clrx        sec        ;error flagInUDret rts; Program 2.16: Assembly implementation of SCI output string.; MC68HC05C8 or MC68HC708XL36; Output a string to the SCI ; Inputs: X points to string;         String ends with 0; Outputs:noneOutString lda 0,X          beq OSdone  ;0 at end          bsr OutChar          incx          bra OutString OSdone    rts; Program 2.17: Assembly implementation of SCI output decimal number.; MC68HC05C8 or MC68HC708XL36; Output unsigned byte to SCI ; Inputs:  Reg A= 0 to 255, ;    print as 3 digit ascii; Outputs: none OutUDec lda #100        bsr div8 ;A=num/100,         add #'0  ;A=100's ascii        bsr OutCh        lda  #10        bsr div8 ;A=num/10,        add #'0  ;A=tens ascii        bsr OutCh        txa        add #'0  ;A=ones ascii        bsr OutCh        rts; Inputs: RegA, RegX; Outputs: A=X/A  quotient;          X=X%A  remainderdiv8    clr quot        tsta        beq divdone        sta divisor        txa      ;a=dividenddivloop cmp divisor        blo divdone        inc quot        sub divisor        bra divloop   divdone tax      ;remainder        lda quot ;quotient        rtsquot    rmb  1divisor rmb  1

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -