ARM LPC2132 startup.s源码分析

本文详细分析了ARM LPC2132的启动文件startup.s,重点讲解了汇编指令,包括伪指令如EQU、AREA、SPACE等的用法,以及ARM汇编指令如LDR、STR、B的功能和示例,为理解ARM处理器的底层工作原理提供了基础。
摘要由CSDN通过智能技术生成

汇编指令整理

伪指令

EQU

  • 作用:用于 为程序中的常量、标号等定义一个等效的字符名称。类似于C语言的#define
  • 用法:<name> EQU <expr>
  • 例子:UND_Stack_Size EQU 0x00000000 ;定义UND_Stack_Size为0x00

AREA

  • 作用:用于声明区域段,数据区,代码区等,并声明该段的一些属性。
  • 用法:AREA <sectionname>, <attr1>, <attr2>...
  • 例子:AREA STACK, NOINIT, READWRITE, ALIGN=3 ;AREA伪指令定义了一个段名为STACK,未初始化的,可读可写的,对其方式为8字节(2^3)对齐的段。

SPACE

  • 作用:用于分配一片连续的存储区域并初始化为0
  • 用法:<label> SPACE <expr>
  • 例子:Stack_Mem SPACE 100 ;分配100字节的连续空间并初始化为0

LDR

  • 作用:用于加载一个立即数或一个地址。
  • 用法:LDR reg, = {expr | label - expr}
  • 例子:LDR R0, =0x01 ;将0x01载入R0寄存器

DCD

  • 作用: 用于分配一片连续的存储单元,并用伪指令中指定的表达式初始化
  • 用法: <label> DCD <expr>
  • 例子:DataTest DCD 4,5,6 ;分配一片连续的字存储单元并初始化

IF、ELSE 和 ENDIF

  • 作用:用于分支判断
  • 用法:
IF Test = TRUE
 程序段1 
ELSE
 程序段2
ENDIF

EXPORT(或GLOBAL)

  • 作用:用于声明内部的一个外部可引用的符号

  • 用法:EXPORT 符号 {[WEAK]}

    • 符号在程序中区分大小写
    • [WEAK] 选项声明其他的同名符号优先于该符号被引用
  • 例子:EXPORT __heap_base ;声明一个名为__heap_base的符号

IMPORT

  • 作用:用于声明外部的一个内部可引用的符号
  • 用法:IMPORT 符号 {[WEAK]}
  • 例子:IMPORT __main ;包含main函数

ARM汇编指令

LDR

  • 作用: 用于从存储器中将一个32位的字数据传送到目的寄存器中。

  • 用法:LDR <reg>, <[addr]>

  • 例子:LDR PC, [R0] ;将R0中的数据装入PC

B

  • 作用:用于程序的跳转
  • 用法:B <label>
  • 例子:B Label ;程序无条件跳转到标号Label处执行

STR

  • 作用: 用于从源寄存器中将一个32位的字数据传送到存储器中。
  • 用法:STR <reg>, <[addr]>
  • 用法:STR R0, [R1], #8 ;将R0中的字数据写入以R1为地址的存储器中,并将新地址R1+8写入R1。
;/*****************************************************************************/
;/* STARTUP.S: Startup file for Philips LPC2000                               */
;/*****************************************************************************/
;/* <<< Use Configuration Wizard in Context Menu >>>                          */ 
;/*****************************************************************************/
;/* This file is part of the uVision/ARM development tools.                   */
;/* Copyright (c) 2005-2007 Keil Software. All rights reserved.               */
;/* This software may only be used under the terms of a valid, current,       */
;/* end user licence from KEIL for a compatible version of KEIL software      */
;/* development tools. Nothing else gives you the right to use this software. */
;/*****************************************************************************/


;/*
; *  The STARTUP.S code is executed after CPU Reset. This file may be 
; *  translated with the following SET symbols. In uVision these SET 
; *  symbols are entered under Options - ASM - Define.
; *
; *  REMAP: when set the startup code initializes the register MEMMAP 
; *  which overwrites the settings of the CPU configuration pins. The 
; *  startup and interrupt vectors are remapped from:
; *     0x00000000  default setting (not remapped)
; *     0x80000000  when EXTMEM_MODE is used
; *     0x40000000  when RAM_MODE is used
; *
; *  EXTMEM_MODE: when set the device is configured for code execution
; *  from external memory starting at address 0x80000000.
; *
; *  RAM_MODE: when set the device is configured for code execution
; *  from on-chip RAM starting at address 0x40000000.
; *
; *  EXTERNAL_MODE: when set the PIN2SEL values are written that enable
; *  the external BUS at startup.
; */


; Standard definitions of Mode bits and Interrupt (I & F) flags in PSRs

Mode_USR        EQU     0x10    ;用户模式
Mode_FIQ        EQU     0x11    ;快中断模式
Mode_IRQ        EQU     0x12    ;中断模式
Mode_SVC        EQU     0x13    ;管理模式
Mode_ABT        EQU     0x17    ;中止模式
Mode_UND        EQU     0x1B    ;未定义模式
Mode_SYS        EQU     0x1F    ;系统模式

I_Bit           EQU     0x80            ; when I bit is set, IRQ is disabled 如果I bit被置一,则
F_Bit           EQU     0x40            ; when F bit is set, FIQ is disabled


;// <h> Stack Configuration (Stack Sizes in Bytes)
;//   <o0> Undefined Mode      <0x0-0xFFFFFFFF:8>
;//   <o1> Supervisor Mode     <0x0-0xFFFFFFFF:8>
;//   <o2> Abort Mode          <0x0-0xFFFFFFFF:8>
;//   <o3> Fast Interrupt Mode <0x0-0xFFFFFFFF:8>
;//   <o4> Interrupt Mode      <0x0-0xFFFFFFFF:8>
;//   <o5> User/System Mode    <0x0-0xFFFFFFFF:8>
;// </h>
;定义各个模式下的堆栈尺寸
UND_Stack_Size  EQU     0x00000000
SVC_Stack_Size  EQU     0x00000008
ABT_Stack_Size  EQU     0x00000000
FIQ_Stack_Size  EQU     0x00000000
IRQ_Stack_Size  EQU     0x00000080
USR_Stack_Size  EQU     0x00000400

ISR_Stack_Size  EQU     (UND_Stack_Size + SVC_Stack_Size + ABT_Stack_Size 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值