Keil C51的STARTUP.A51详解
扫描二维码
随时随地手机看文章
$NOMOD51;Ax51宏汇编器控制命令:禁止预定义的8051
;------------------------------------------------------------------------------
; This file is part of the C51 Compiler package
; Copyright (c) 1988-2002 Keil Elektronik GmbH and Keil Software, Inc.
;------------------------------------------------------------------------------
; STARTUP.A51: This code is executed after processor reset.
; STARTUP.A51: STARTUP.A51文件所生成的代码将在单片机复位后被执行!
; To translate this file use A51 with the following invocation:
;将按照下面的命令行语句调用A51编译器进行编译产生目标文件
; A51 STARTUP.A51
;
; To link the modified STARTUP.OBJ file to your application use the following
; BL51 invocation:
;将按照下面的命令行语句调用BL51连接器把STARTUP.OBJ定位连接到您的程序代码中
; BL51, STARTUP.OBJ
;
;------------------------------------------------------------------------------
;
; User-defined Power-On Initialization of Memory
;自定义上电后需要初始化的储存区域
; With the following EQU statements the initialization of memory
; at processor reset can be defined:
;使用下列EQU伪指令定义初始化的存储区域在单片机复位后定义生效
; ; the absolute start-address of IDATA memory is always 0
IDATALEN EQU 80H ; the length of IDATA memory in bytes.
; IDATA(间接寻址区)其起始地址固定为0;IDATALEN用于指定需要初始化的IDATA区长度(以字节为单位)*
XDATASTART EQU 0H ; the absolute start-address of XDATA memory
XDATALEN EQU 0H ; the length of XDATA memory in bytes.
;XDATA(外部直接寻址区)XDATASTART用于指定需要初始化的XDATA区起始地址
;XDATALEN用于指定需要初始化的XDATA区长度(以字节为单位)*
PDATASTART EQU 0H ; the absolute start-address of PDATA memory
PDATALEN EQU 0H ; the length of PDATA memory in bytes.
;PDATA(页寻址区)PDATASTART用于指定需要初始化的PDATA区起始地址
;PDATALEN用于指定需要初始化的;PDATA区长度(以字节为单位)*
; Notes: The IDATA space overlaps physically the DATA and BIT areas of the
; 8051 CPU. At minimum the memory space occupied from the C51
; run-time routines must be set to zero.
;注释:8051中IDATA区物理上已经包括了DATA区(直接寻址区)以及BIT区(位寻址区)。C51(库)占用了最小化内存空间,运行时程序需要把它设为0
;------------------------------------------------------------------------------
;
; Reentrant Stack Initilization
;重入堆栈初始化
; The following EQU statements define the stack pointer for reentrant
; functions and initialized it:
;下面的EQU语句定义重入函数的堆栈指针并初始化它
; Stack Space for reentrant functions in the SMALL model.
; SMALL模式下的重入函数的堆栈空间
IBPSTACK EQU 0 ; set to 1 if small reentrant is used.
;如果再SMALL模式下使用重入则设为1
IBPSTACKTOP EQU 0FFH+1 ; set top of stack to highest location+1.
;设置堆栈顶最高位置+1
;
; Stack Space for reentrant functions in the LARGE model.
; LARGE模式下的重入函数的堆栈空间
XBPSTACK EQU 0 ; set to 1 if large reentrant is used.
;如果再LARGE模式下使用重入则设为1
XBPSTACKTOP EQU 0FFFFH+1; set top of stack to highest location+1.
;设置堆栈顶最高位置+1
;
; Stack Space for reentrant functions in the COMPACT model.
; COMPACT模式下的重入函数的堆栈空间
PBPSTACK EQU 0 ; set to 1 if compact reentrant is used.
;如果再COMPACT模式下使用重入则设为1
PBPSTACKTOP EQU 0FFFFH+1; set top of stack to highest location+1.
;设置堆栈顶最高位置+1
;
;------------------------------------------------------------------------------
;
; Page Definition for Using the Compact Model with 64 KByte xdata RAM
;使用COMPACT模式时为64KB的XDATA RAM定义页
; The following EQU statements define the xdata page used for pdata
; variables. The EQU PPAGE must conform with the PPAGE control used
; in the linker invocation.
;下面的EQU语句定义PDATA变量的使用了XDATA页
PPAGEENABLE EQU 0 ; set to 1 if pdata object are used.
;如果使用PDATA页则设为1
;
PPAGE EQU 0 ; define PPAGE number.
;定义页号
;
PPAGE_SFR DATA 0A0H ; SFR that supplies uppermost address byte
;SFR的最高地址字节
; (most 8051 variants use P2 as uppermost address byte)
; (大多数8051变量要用P2的最高地址字节)
;------------------------------------------------------------------------------
; Standard SFR Symbols
;标准SFR符号
ACC DATA 0E0H
B DATA 0F0H
SP DATA 81H
DPL DATA 82H
DPH DATA 83H
NAME ?C_STARTUP
?C_C51STARTUP SEGMENT CODE
?STACK SEGMENT IDATA
RSEG ?STACK
DS 1
EXTRN CODE (?C_START)
;外部代码(这个标号将代表用户程序的启始地址)
PUBLIC ?C_STARTUP
;给外部使用的符号
CSEG AT 0
;在code段的0地址处放以下代码(使用AT指令进行绝对地址的定位)
?C_STARTUP: LJMP STARTUP1
RSEG ?C_C51STARTUP
STARTUP1:
IF IDATALEN <> 0
;如果长度大于1则初始化IDATA
MOV R0,#IDATALEN - 1
CLR A
IDATALOOP: MOV @R0,A
DJNZ R0,IDATALOOP
ENDIF
IF XDATALEN <> 0
;如果长度大于1则初始化XDATA
MOV DPTR,#XDATASTART
MOV R7,#LOW (XDATALEN)
IF (LOW (XDATALEN)) <> 0
;预置初始化时的外循环次数到R6
MOV R6,#(HIGH (XDATALEN)) +1
ELSE
MOV R6,#HIGH (XDATALEN)
ENDIF
CLR A
XDATALOOP: MOVX @DPTR,A
INC DPTR
DJNZ R7,XDATALOOP
DJNZ R6,XDATALOOP
ENDIF