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

📄 chap4.asm

📁 摩托罗拉Mc6811利程
💻 ASM
📖 第 1 页 / 共 2 页
字号:
; Chapter 4 6811 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  2    Temporary global variable* Input parameters: Reg X,Y contain 2 16 bit numbers* Output parameter: Reg X is returned with the averageAVE     sty  Second  Save the second number in memory         xgdx         Reg D contains first number        addd Second  Reg D=First+Second        lsrd         (First+Second)/2        adcb #0      round up?        adca #0        xgdx        rts; Program 4.2. This subroutine is also nonreentrant because of the read-modify-write access to a global. Money rmb  2      bank balance implemented as a global* add $100 to the accountmore  ldd  Money	where Money is a global variable	addd #100	std  Money	Money=Money+100      rts; Program 4.4. This assembly subroutine is nonreentrant because of the write-read access to a global. temp  rmb  2       temporary result implemented as a global* calculate RegX=RegX+2*RegDmac	stx  temp	Save X so that it can be added	lsld        RegD=2*RegD      addd temp	RegD=RegX+2*RegD			xgdx        RegX=RegX+2*RegD      rts ; Program 4.6. This assembly subroutine is nonreentrant because of the multi-step write access to a global. Info  rmb  4       32-bit data implemented as a global* set the variable using RegX and RegYset	stx  Info	 Info is a 32 bit global variable	sty  Info+2	      rts; Program 4.8. This assembly subroutine is reentrant because it does not write to any globals. * Input parameters: Reg X,Y contain 2 16 bit numbers* Output parameter: Reg X is returned with the averageAVE     pshy         Save the second number on the stack        tsy          Reg Y points the Second number        xgdx         Reg D contains first number        addd 0,Y     Reg D=First+Second        lsrd         (First+Second)/2        adcb #0      round up?        adca #0        xgdx        puly        rts; 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 B 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        stab 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 B contains an 8 bit message* Output parameter: Reg CC (C bit) is 1 for OK, 0 for busy errorSEND    clc          Initialize carry=0        tpa          save current interrupt state        psha        sei          disable interrupts during vulnerable window        tst  Status  check if mailbox is empty        bmi  Busy    full, so return with C=0        staa Message store        dec  Status  signify it is now contains a message        pula        oraa #1      OK, so return with C=1        pshaBusy    pula         restore interrupt status        tap        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      bita #0        operation successful, so return with Z=1Out   rts; Program 4.13. Code fragments showing the basic idea of a FIFO. GetPt  rmb 2   Pointer to oldest data, next to be removed by GETPutPt  rmb 2   Pointer to free memory, place to PUT next data* Reg A contains byte to store into the FIFOPutFifo  ldx  PutPt   Reg X points to free place     staa ,X      Store data into FIFO     inx          Update pointer     stx  PutPt        rts* Reg A returned with byte from FIFOGetFifo  ldx  GetPt  Reg X points to oldest data     ldaa ,X     Read data from FIFO     inx         Update pointer     stx  GetPt       rts; Program 4.15. Initialization of a two pointer FIFO. * Two pointer implementation of the FIFO FifoSize  equ  10    Number of 8 bit data in the Fifo, less onePutPt     rmb  2     Pointer of where to put next */GetPt     rmb  2     Pointer of where to get next* FIFO is  empty if PutPt=GetPt * FIFO is full  if PutPt+1=GetPt (with wrap)Fifo      rmb  FifoSize    The statically allocated fifo data ***********Initialize FIFO******************* No parametersInitFifo  ldx #Fifo          tpa          sei        make atomic, entering critical section          stx PutPt          stx GetPt  Empty when PutPt=GetPt           tap        end critical section, restore CCR          rts; Program 4.16. Assembly routine to put into a two pointer FIFO. ***********Put a byte into the FIFO******************* Input  RegA contains 8 bit data to put* Output RegA is -1 if successful, 0 if data not storedPutFifo   psha          tpa          tab          pula          pshb            save old CCR          sei             make atomic, entering critical section          ldx  PutPt      RegX is Temporary put pointer          staa 0,x        Try to put data into fifo           inx          cpx  #Fifo+FifoSize          bne  PutNoWrap  skip if no wrapping needed          ldx  #Fifo      Wrap PutNoWrap clra            assume it will fail          cpx  GetPt      Full if now the same          beq  PutDone          coma            RegA=-1 means OK          stx  PutPtPutDone   tab        end critical section          pula          tpa        restore CCR to previous value          tba          rts; Program 4.17. Assembly routine to get from a two pointer FIFO. ***********Get a byte from the FIFO******************* Input  RegX points to place for 8 bit data from Get* Output RegA is -1 if successful, 0 if Fifo was empty when calledGetFifo   tpa          psha            save old CCR          sei             make atomic, entering critical section          clra            assume it will fail          ldy  GetPt            cpx  PutPt      Empty if initially the same          beq  GetDone          coma            RegA=-1 means OK          ldab 0,y        Data from FIFO          stab 0,x        Return by reference           iny          cpy  #Fifo+FifoSize          bne  GetNoWrap  skip if no wrapping needed          ldy  #Fifo      Wrap GetNoWrap sty  GetPtGetDone   tab        end critical section          pula          tpa        restore CCR to previous value          tba          rts; Program 4.19. Initialization of a two pointer with counter FIFO. * Pointer,counter implementation of the FIFO FifoSize   equ  10    Number of 8 bit data in the FifoPutPt      rmb  2     Pointer of where to put next GetPt      rmb  2     Pointer of where to get nextSize       rmb  1* FIFO is empty if Size=0 * FIFO is full  if Size=FifoSize Fifo       rmb  FifoSize    The statically allocated fifo data ***********Initialize FIFO******************* No parametersInitFifo   tpa           sei         make atomic, entering critical section           ldx  #Fifo           stx  PutPt           stx  GetPt  Empty when Size == 0           clr  Size            tap         end critical section           rts; Program 4.20. Assembly routine to put into a two pointer with counter FIFO. ***********Put a byte into the FIFO******************* Input  RegA contains 8 bit data to put* Output RegA is -1 if successful, 0 if data not storedPutFifo    psha           tpa           tab           pula           pshb            save old CCR           sei             make atomic, entering critical section           ldab Size           cmpb #FifoSize  Full if Size==FifoSize           bne  PutNotFull           clra           bra  PutDonePutNotFull incb           stab Size       Size++           ldx  PutPt            staa 0,x        Put data into fifo            inx           cpx  #Fifo+FifoSize           bne  PutNoWrap  skip if no wrapping needed           ldx  #Fifo      Wrap PutNoWrap  ldaa #-1        success means OK           stx  PutPtPutDone    tab        end critical section           pula           tpa        restore CCR to previous value           tba           rts; Program 4.21. Assembly routine to get from a two pointer with counter FIFO. ***********Get a byte from the FIFO******************* Input  RegX points to place for 8 bit data from Get* Output RegA is -1 if successful, 0 if Fifo was empty when calledGetFifo tpa        psha    save old CCR        sei     make atomic, entering critical section        clra       assume it will fail        tst  Size        beq  GetDone        dec  Size        ldy  GetPt          coma          RegA=-1 means OK        ldab 0,y      Data from FIFO        stab 0,x      Return by reference         iny        cpy  #Fifo+FifoSize        bne  GetNoWrap  skip if no wrapping needed        ldy  #Fifo      Wrap GetNoWrap sty GetPtGetDone tab        end critical section        pula        tpa        restore CCR to previous value        tba        rts; Program 4.23. Initialization of a two index with counter FIFO. * Index,counter implementation of the FIFO FifoSize equ  10    Number of 8 bit data in the Fifo PutI     rmb  1     Index of where to put nextGetI     rmb  1     Index of where to get nextSize     rmb  1* FIFO is empty if Size=0 * FIFO is full  if Size=FifoSize Fifo       rmb  FifoSize    The statically allocated fifo data ***********Initialize FIFO******************* No parametersInitFifo   tpa           sei        make atomic, entering critical section           clr  PutI           clr  GetI           clr  Size  Empty when Size == 0            tap        end critical section           rts; Program 4.24. Assembly routine to put into a two index with counter FIFO. ***********Put a byte into the FIFO******************* Input  RegA contains 8 bit data to put* Output RegA is -1 if successful, 0 if data not storedPutFifo    psha

⌨️ 快捷键说明

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