?? chap2.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 + -