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

📄 chap4.asm

📁 摩托罗拉Mc6805利程
💻 ASM
字号:
; Chapter 4 6805 assembly language programs; Jonathan W. Valvano; This software accompanies the book,; Real Time Embedded Systems published by Brooks Cole;; Program 4.1. This subroutine is nonreentrant because of the read-modify-write access to a global. Second  rmb  1    Temporary global variable* Input parameters: Reg A,X contain 2 8 bit numbers* Output parameter: Reg A is returned with the averageAVE     stx  Second  Save the second number in memory         add  Second  Reg A=First+Second        lsra         (First+Second)/2        adc  #0      round up?        rts; Program 4.2. This subroutine is also nonreentrant because of the read-modify-write access to a global. Money rmb  1      bank balance implemented as a global* add 10 to the accountmore  lda  Money	where Money is a global variable	add #10	sta  Money	Money=Money+10      rts; Program 4.4. This assembly subroutine is nonreentrant because of the write-read access to a global. temp  rmb  1       temporary result implemented as a global* calculate RegA=RegX+2*RegAmac	stx  temp	Save X so that it can be added	lsla        RegA=2*RegA      add temp	RegA=RegX+2*RegA		      rts ; Program 4.6. This assembly subroutine is nonreentrant because of the multi-step write access to a global. Info  rmb  2       16-bit data implemented as a global* set the variable using RegA and RegXset	sta  Info	 Info is a 16 bit global variable	stx  Info+1	      rts; Program 4.8. This assembly subroutine is reentrant because it does not write to any globals. ; not possible on the 6805, see 6808, 6811 or 6812; Program 4.9. This assembly subroutine is nonreentrant because of the read-modify-write access to a global. Status   rmb  1    0 means empty, -1 means it contains somethingMessage  rmb  1    data to be communicated* Input parameter: Reg X contains an 8 bit message* Output parameter: Reg CC (C bit) is 1 for OK, 0 for busy errorSEND    tst  Status  check if mailbox is empty        bmi  Busy    full, can't store, so return with C=0        stx  Message store        dec  Status  signify it is now contains a message        sec          stored OK, so return with C=1Busy    rts; Program 4.10. This assembly subroutine is reentrant because it disables interrupts during the critical section. Status   rmb  1    0 means empty, -1 means it contains somethingMessage  rmb  1    data to be communicated* Input parameter: Reg X contains an 8 bit message* Output parameter: Reg CC (C bit) is 1 for OK, 0 for busy errorSEND    clc          Initialize carry=0        sei          disable interrupts during vulnerable window        tst  Status  check if mailbox is empty        bmi  Busy    full, so return with C=0        stx  Message store        dec  Status  signify it is now contains a message        sec      OK, so return with C=1Busy    cli         restore interrupt status        rts; Program 4.12. This assembly subroutine can be used as part of a binary semaphore. * Global parameter: Semi4 is the memory location to test and set* If the location is zero, it will set it (make it -1)*      and return Reg CC (Z bit) is 1 for OK* If the location is nonzero, it will return Reg CC (Z bit) = 0Semi4 fcb  0         Semaphore is initially freeTAS   tst  Semi4     check if already set      bne  Out       busy, operation failed, so return with Z=0      dec  Semi4     signify it is now busy      bit  #0        operation successful, so return with Z=1Out   rts; Program 4.27. Example of a vectored interrupt. ; MC68HC705J1ATimeHan lda #$08  ;TOFR        sta TSCR  ;clear TOF;*Timer interrupt calculations*        rtiExtHan  lda ISCR        ora #$02  ;IRQR        sta ISCR  ;clear IRQ;*External interrupt calculations*        rti        org $07F8  ;timer overflow        fdb TimeHan        org $07FA  ;IRQ external        fdb ExtHan; Program 4.28. Example of a polled interrupt. ; MC68HC705J1AExtHan brset 0 PORTA PA0Han       brset 1 PORTA PA1Han       bset  1,ISCR ;IRQR       rti          ;no more  PA0Han ;*PA0 interrupt calculations*       bra ExtHan ;otherPA1Han ;*PA1 interrupt calculations*       bra ExtHan ;other       org $07FA  ;IRQ external       fdb ExtHan; Program 4.29. Interrupting keyboard software. ; MC68HC705J1A; PA7-PA1 inputs = keyboard DATA; PA0=STROBE interrupt on riseInit  sei         ; make atomic      clr  DDRA   ;all inputs      mov #$82,ISCR  ;arm,clr IRQ      jsr  InitFifo      cli        ;Enable IRQ      rts    ExtHan brset 0,PORTA,KeyHan       swi         ;errorKeyHan lda  PORTA ;data       lsra       jsr  PutFifo       bset 1,ISCR ;ack       rti       org $07FA  ;IRQ external       fdb ExtHan; Program 4.31. Helper routines for the printer interface. ; MC68HC705J1A;*****goes in RAM**************OK    rmb 1   ;0=busy, 1=doneLine  rmb 20  ;ASCII, end with 0Pt    rmb 2   ;pointer to LinePt2   rmb 2   ;temporary;*****goes in ROM**************;Input RegX=>stringFill  stx Pt2 ;Pt2=>string      ldx #Line       stx Pt    ;init pointerFloop ldx Pt2      lda 0,X   ;read data      incx      stx Pt2      ldx Pt      sta 0,X   ;write data      incx      stx Pt      tst       ;end?      bne Floop      ldx #Line       stx Pt    ;init pointer      clr OK      rts;Return RegA=dataGet   ldx Pt      lda 0,X   ;return RegA=data      incx      stx Pt      rts; Program 4.32. Initialization routines for the printer interface. ; MC68HC705J1A; PA7-PA1 outputs = printer DATA; PB0=START; PA0=READY interrupt on rise;Input RegX=>stringInit sei        ; make atomic     bsr Fill   ;Init global      lda #$01     sta DDRB  ;PB0 output     lda #$FE     sta DDRA  ;PA outputs     lda #$01     sta PORTB ;START=1     lda #$82     sta ISCR  ;arm,clr IRQ     bsr Get     bsr Out    ;start first     cli        ;Enable IRQ     rts Out  clr PORTB  ;START=0     lsla       ;bits7:1     sta PORTA  ;write DATA     inc PORTB  ;START=1     rts; Program 4.33. ISR routines for the printer interface. ; MC68HC705J1AExtHan brset 0,PORTA,PrtHan       swi         ;errorPrtHan bset 1,ISCR ;IRQR       bsr  Get       tsta       beq  Disarm       bsr  Out    ;start next       bra  Done Disarm clr  ISCR   ;disarm IRQ2       inc  OK     ;line completeDone   rti       org $07FA  ;IRQ external       fdb ExtHan

⌨️ 快捷键说明

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