汇编指令整理
伪指令
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