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

📄 start.asm

📁 富士通单片机的iic源码 原创! 精华
💻 ASM
📖 第 1 页 / 共 4 页
字号:
#    endif
#  endif

          MOV  I:ROMM, #ROMMIRROR
#endif

;====================================================================
; 6.7  Copy initial values to data areas.
;====================================================================
;
; Each C-module has its own __far INIT section. The names are generic.
; DCONST_module contains the initialisers for the far data of the one
; module. INIT_module reserves the RAM area, which has to be loaded
; with the data from DCONST_module. ("module" is the name of the *.c
; file)
; All separated DCONST_module/INIT_module areas are described in
; DTRANS section by start addresses and length of each far section.
;   0000 1. source address (ROM)
;   0004 1. destination address (RAM)
;   0008 length of sections 1
;   000A 2. source address  (ROM)
;   000E 2. destination address (RAM)
;   0012 length of sections 2
;   0014 3. source address ...
; In addition the start-up file adds the descriptors of the __near
; sections to this table. The order of the descriptors in this table
; depends on the linkage order.
;====================================================================
          MOV  A, #BNKSEC DTRANS   ; get bank of table
          MOV  DTB, A              ; store bank in DTB
          MOVW RW1, #DTRANS        ; get start offset of table
          OR   CCR, #H'20          ; System stack flag set (SSB used)
          BRA  LABEL2              ; branch to loop condition
LABEL1:
          MOVW A, @RW1+6           ; get bank of destination
          MOV  SSB, A              ; save dest bank in SSB
          MOVW A, @RW1+2           ; get source bank
          MOV  ADB, A              ; save source bank in ADB
          MOVW A, @RW1+4           ; move destination addr in AL
          MOVW A, @RW1             ; AL ->AH, src addr -> AL
          MOVW RW0, @RW1+8         ; number of bytes to copy -> RW0
          MOVSI     SPB, ADB       ; copy data
          MOVN A, #10              ; length of one table entry is 10
          ADDW RW1, A              ; set pointer to next table entry
LABEL2:
          MOVW A, RW1              ; get address of next block
          SUBW A, #DTRANS          ; sub address of first block
          CMPW A, #SIZEOF (DTRANS) ; all blocks processed ?
          BNE  LABEL1              ; if not, branch

;====================================================================
; 6.8   Clear uninitialised data areas to zero
;====================================================================
;
; Each C-module has its own __far DATA section. The names are generic.
; DATA_module contains the reserved area (RAM) to be cleared.
; ("module" is the name of the *.c file)
; All separated DATA_module areas are described in DCLEAR section by
; start addresses and length of all far section.
;   0000 1. section address (RAM)
;   0004 length of section 1
;   0006 2. section address (RAM)
;   000A length of section 2
;   000C 3. section address (RAM)
;   0010 length of section 3 ...
; In addition the start-up file adds the descriptors of the __near
; section. to this table. The order of the descriptors in this table
; depends on the linkage order.
;====================================================================
          MOV  A, #BNKSEC DCLEAR   ; get bank of table
          MOV  DTB, A              ; store bank in DTB
          MOVW RW1, #DCLEAR        ; get start offset of table
          BRA  LABEL4              ; branch to loop condition
LABEL3:
          MOV  A, @RW1+2           ; get section bank
          MOV  ADB, A              ; save section bank in ADB
          MOVW RW0, @RW1+4         ; number of bytes to copy -> RW0
          MOVW A, @RW1             ; move section addr in AL
          MOVN A, #0               ; AL ->AH, init value -> AL
          FILSI     ADB            ; write 0 to section
          MOVN A, #6               ; length of one table entry is 6
          ADDW RW1, A              ; set pointer to next table entry
LABEL4:
          MOVW A, RW1              ; get address of next block
          SUBW A, #DCLEAR          ; sub address of first block
          CMPW A, #SIZEOF (DCLEAR) ; all blocks processed ?
          BNE  LABEL3              ; if not, branch

;====================================================================
; 6.9  Prepare stacks and set the default stack type
;====================================================================

          AND  CCR,#H'DF            ; clear system stack flag
          MOVL A, #(__userstack_top) & ~1
          MOVW SP,A                 ; load offset of stack top to pointer
          SWAPW                     ; swap higher word to AL
          MOV  USB, A               ; set bank

#if STACK_FILL == ON                ; preset the stack
          MOV  ADB, A
          MOVW A, #USTACK           ; load start stack address to AL
          MOVW A, #STACK_PATTERN    ; AL -> AH, pattern in AL
          MOVW RW0, #SIZEOF(USTACK) / 2 ; get byte count
          FILSWI    ADB             ; write pattern to stack
#endif

          OR   CCR,#H'20            ; set System stack flag
          MOVL A, #(__systemstack_top) & ~1
          MOVW SP,A                 ; load offset of stack top to pointer
          SWAPW                     ; swap higher word to AL
          MOV  SSB, A               ; set bank

#if STACK_FILL == ON                ; preset the stack
          MOV  ADB, A
          MOVW A, #SSTACK            ; load start stack address to AL
          MOVW A, #STACK_PATTERN    ; AL -> AH, pattern in AL
          MOVW RW0, #SIZEOF(SSTACK) / 2; get byte count
          FILSWI    ADB             ; write pattern to stack
#endif

#if STACKUSE == USRSTACK
          AND  CCR,#H'DF            ; clear system stack flag
#endif


;   Following macros are needed because of the AUTOMODEL option. If the
;   model is not known while assembling the module, one has to expect
;   completion of streaminit() by RET or RETP. Because RET removes 2 bytes
;   from stack and RETP removes 4 bytes from stack, SP is reloaded.

#  macro RELOAD_SP

#if STACKUSE == USRSTACK
          MOVW A, #(__userstack_top) & ~1
#else
          MOVW A, #(__systemstack_top) & ~1
#endif
          MOVW SP,A
#  endm

;====================================================================
; 6.10  Set Data Bank Register (DTB) and Direct Page Register (DPR)
;====================================================================
          MOV  A,#BNKSEC DATA          ; User data bank offset
          MOV  DTB,A

          MOV  A,#PAGE DIRDATA_S       ; User direct page
          MOV  DPR,A

;====================================================================
; 6.11  Wait for PLL to stabilise
;====================================================================

#if CLOCKSPEED > MAINCLOCK && CLOCKWAIT == ON
no_PLL_yet:
          BBS  I:CKSCR:6,no_PLL_yet    ; check MCM and wait for
                                       ; PLL to stabilize
#endif

;====================================================================
; 6.12  Initialise Low-Level Library Interface
;====================================================================
;
; Call lib init function and reload stack afterwards, if AUTOMODEL
;====================================================================
#if CLIBINIT == ON
#  if MEMMODEL == SMALL || MEMMODEL == COMPACT
          CALL __stream_init       ; initialise library IO
#  else                            ; MEDIUM, LARGE, AUTOMODEL
          CALLP __stream_init      ; initialise library IO
#    if MEMMODEL == AUTOMODEL
          RELOAD_SP                ; reload stack since stream_init was
                                   ; possibly left by RET (not RETP)
#    endif  ; AUTOMODEL
#  endif  ; MEDIUM, LARGE, AUTOMODEL
#endif  ; LIBINI

;====================================================================
; 6.13  Call C-language main function
;====================================================================
#if MEMMODEL == SMALL || MEMMODEL == COMPACT
          CALL _main               ; Start main function
#else                              ; MEDIUM, LARGE, AUTOMODEL
          CALLP _main              ; Start main function
                                   ; ignore remaining word on stack,
                                   ; if main was completed by RET
;====================================================================
; 6.14  Shut down library
;====================================================================
#endif
#if CLIBINIT == ON
#  if MEMMODEL == SMALL || MEMMODEL == COMPACT
          CALL _exit
#  else                            ; MEDIUM, LARGE, AUTOMODEL
          CALLP _exit              ; ignore remaining word on stack,
                                   ; if main was completed by RET
#  endif
__exit:
#endif

;====================================================================
; 6.15  Program end loop
;====================================================================

end:      BRA  end                 ; Loop


;====================================================================
; 6.16  Configuration stamp in ROM (currently test only)
;====================================================================

;   Bit7     Bit6     Bit5     Bit4     Bit3     Bit2     Bit1     Bit0
;+--------+--------+--------+--------+--------+--------+--------+--------+
;|                     Format ID of version stamp "V"                    |
;+--------+--------+--------+--------+--------+--------+--------+--------+
;|                     Format ID of version stamp "S"                    |
;+--------+--------+--------+--------+--------+--------+--------+--------+
;|                 Format version number of version stamp                |
;+--------+--------+--------+--------+--------+--------+--------+--------+
;|              FAMILY (4)           | CONST  |         MODEL (3)        |
;+--------+--------+--------+--------+--------+--------+--------+--------+
;|STACKUSE|STACKRES|  FILL  | LIBINIT| STAMP  |REG_PASS|        |        |
;+--------+--------+--------+--------+--------+--------+--------+--------+
;| RESVEC | RAMCODE|        |          REGISTER BANK POINTER (5)         |
;+--------+--------+--------+--------+--------+--------+--------+--------+
;|           CLOCKSPEED (4)          |  WAIT  | ADDRESS| MIRROR |        |
;+--------+--------+--------+--------+--------+--------+--------+--------+
;|   BUSMODE (2)   | AUTOWAIT_IO (2) | AUTOWAIT_LO (2) | AUTOWAIT_HI (2) |
;+--------+--------+--------+--------+--------+--------+--------+--------+
;|                               ADDR_PINS                               |
;+--------+--------+--------+--------+--------+--------+--------+--------+
;|                               BUS_SIGNAL                              |
;+--------+--------+--------+--------+--------+--------+--------+--------+
;|                          VERSION 1st character                        |
;+--------+--------+--------+--------+--------+--------+--------+--------+
;|                          VERSION 2nd character                        |
;+--------+--------+--------+--------+--------+--------+--------+--------+
;                                   ...
;+--------+--------+--------+--------+--------+--------+--------+--------+
;|                                  NULL                                 |
;+--------+--------+--------+--------+--------+--------+--------+--------+

#if CONFIG_STAMP == ON

stamp:
  .DATA.B 'V', 'S', 1                 ; version stamp format 1
  .DATA.B endstamp - stamp            ; size of format stamp

  .DATA.B (FAMILY << 4) | (CONSTDATA << 3) |  MEMMODEL
  .DATA.B STACKUSE<<7 | STACK_RESERVE<<6 | STACK_FILL<<5 | CLIBINIT<<4 |CONFIG_STAMP<<3 |!!__REG_PASS__<<2
  .DATA.B RESET_VECTOR << 7 | COPY_RAMCODE << 6 | REGBANK
  .DATA.B CLOCKSPEED<<4 | CLOCKWAIT<<3 | ADDRESSMODE<<2 | ROMMIRROR<<1
  .DATA.B BUSMODE<<6 | AUTOWAIT_IO<<4 | AUTOWAIT_LO<<2 | AUTOWAIT_HI
  .DATA.B ADDR_PINS
  .DATA.B BUS_SIGNAL

  .SDATA VERSION, "\0"
endstamp:

#endif

;====================================================================
; 6.17  Debug address specification
;====================================================================
          .END notresetyet         ; define debugger start address

;====================================================================
; ----------------------- End of Start-up file ---------------------
;====================================================================

⌨️ 快捷键说明

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