Presentation is loading. Please wait.

Presentation is loading. Please wait.

College of Computer Science & Technology

Similar presentations


Presentation on theme: "College of Computer Science & Technology"— Presentation transcript:

1 College of Computer Science & Technology
第三章 ARM汇编编程 College of Computer Science & Technology

2 ARM汇编语言伪指令(Directives)
鲁东大学 LUDONG UNIVERSITY 什么是伪指令: 由汇编器提供的指令,指导汇编程序对代码进行汇编,辅助编程人员进行汇编编程 机器指令(Instructions) 运行期间由机器执行 伪指令(Directives,Pseudo)-由汇编器处理 ①汇编语言指示符-指示汇编器进行相应的操作 ② 操作伪指令-汇编器汇编成对应机器指令

3 伪指令举例 AREA ThumbSub, CODE, READONLY ENTRY CODE32 ;ARM header
鲁东大学 LUDONG UNIVERSITY AREA ThumbSub, CODE, READONLY ENTRY CODE32 ;ARM header ADR r0, start + 1 CODE16 ;Thumb. start MOV r0, #10 doadd MOV pc, lr END

4 ARM汇编语言伪指令 杂项伪指令 符号定义伪指令 数据定义伪指令 操作伪指令 汇编控制伪指令 报告伪指令
鲁东大学 LUDONG UNIVERSITY 杂项伪指令 符号定义伪指令 数据定义伪指令 操作伪指令 汇编控制伪指令 报告伪指令

5 符号定义伪指令 GBLA, GBLL, GBLS LCLA, LCLL, LCLS SETA, SETL,SETS
鲁东大学 LUDONG UNIVERSITY 符号定义指令(Symbol definition directives):用于定义ARM汇编程序中的变量(实为常量),可进行重新赋值。 GBLA, GBLL, GBLS LCLA, LCLL, LCLS SETA, SETL,SETS

6 GBLA, GBLL, GBLS 全局变量声明 -- 声明一个全局的算术、逻辑和串变量 Directives Variable Type
鲁东大学 LUDONG UNIVERSITY GBLA, GBLL, GBLS -- 声明一个全局的算术、逻辑和串变量 有效作用范围:The scope of the variable is limited to the source file that contains it. Directives Variable Type Initial Value GBLA arithmetic GBLL logical {FALSE} GBLS string ""

7 SETA, SETL, SETS 变量赋值 --给一个算术、逻辑、串变量赋值 Example: GLBA a GLBS abc
鲁东大学 LUDONG UNIVERSITY SETA, SETL, SETS --给一个算术、逻辑、串变量赋值 Example: GLBA a GLBS abc GLBS def a SETA 256*256 abc SETS "this string contains only one "" double quote" def SETS "this string contains only one $$ dollar symbol"

8 VersionString SETS "Version 1.0"
Example 鲁东大学 LUDONG UNIVERSITY GBLA VersionNumber VersionNumber SETA 21 GBLL Debug Debug SETL {TRUE} GBLS VersionString VersionString SETS "Version 1.0"

9 LCLA, LCLL, LCLS 局部变量声明 --声明一个局部的算术、逻辑、串变量 Directives Variable Type
鲁东大学 LUDONG UNIVERSITY LCLA, LCLL, LCLS --声明一个局部的算术、逻辑、串变量 有效作用范围:The scope of the variable is limited to a particular macro that contains it. Directives Variable Type Initial Value LCLA arithmetic LCLL logical {FALSE} LCLS string ""

10 $label message $a ;Macro prototype line
Example 鲁东大学 LUDONG UNIVERSITY MACRO ; Declare a macro $label message $a ;Macro prototype line LCLS err ; Declare local string variable err SETS "error no: " ; Set value of err MEND

11 数据定义伪指令 SPACE DCB DCD, DCDU MAP, FIELD
鲁东大学 LUDONG UNIVERSITY 数据定义指令(Data definition directives):用于进行数据空间分配。 SPACE DCB DCD, DCDU MAP, FIELD

12 SPACE The SPACE directive reserves a zeroed block of memory.
鲁东大学 LUDONG UNIVERSITY The SPACE directive reserves a zeroed block of memory. 分配一块内存单元,并用0初始化。 Example AREA MyData, DATA, READWRITE data1 SPACE 255 ; defines 255 bytes of zeroed store

13 DCB 鲁东大学 LUDONG UNIVERSITY The DCB directive allocates one or more bytes of memory, and defines the initial values of the memory. 分配一段字节内存单元,并用伪指令中的expr初始化。 Syntax:{label} DCB expr {,expr}... Example DISPTAB DCB 0x33,0x43,0x76 ERRSTR DCB “Send data is error!”,0

14 DCD,DCDU 鲁东大学 LUDONG UNIVERSITY The DCD directive allocates one or more words of memory, aligned on 4-byte boundaries. DCDU is the same, except that the memory alignment is arbitrary. 分配一段字内存单元,并用伪指令中的expr初始化。 DCD分配的内存单元需要字对齐,而DCDU则不需要 Syntax:{label} DCD{U} expr {,expr}...

15 Example for DCD,DCDU 鲁东大学 LUDONG UNIVERSITY

16 字对齐和非字对齐 DCB 255 ; Now misaligned ... data3 DCDU 20 data3 DCD 20
鲁东大学 LUDONG UNIVERSITY DCB ; Now misaligned ... data3 DCDU 20 data3 DCD 20

17 directive sets the origin of a storage map to a specified address.
MAP,FIELD 鲁东大学 LUDONG UNIVERSITY MAP directive sets the origin of a storage map to a specified address. 将内存区(表)的首地址映射到一个指定地址 ^ is a synonym (同义词)for MAP. Syntax MAP expr{,base-register} Example MAP 0,r9 MAP 0xff,r9 ^ 0,r9

18 Example MAP,FIELD FIELD # is a synonym for FIELD. Syntax MAP 0,r9
鲁东大学 LUDONG UNIVERSITY FIELD directive describes space within a storage map that has been defined using the MAP directive. # is a synonym for FIELD. Syntax {label} FIELD expr Example MAP 0,r9 Integer FIELD 4 Lab FIELD 4 LDR r0,Lab

19 MAP,FIELD-EXAMPLE StartOfMyTable EQU 0x1000 MAP 0x1000 Integer FIELD 4
鲁东大学 LUDONG UNIVERSITY StartOfMyTable EQU 0x1000 MAP 0x1000 Integer FIELD 4 Integer2 FIELD 4 String FIELD 100 Array FIELD 128 BitMask FIELD 4 对于结构化表结构的存,取操作 MOV r1,#1 LDR r0,=Integer STR r1,[r0] LDR r2,[r0]

20 操作伪指令-pseudoinstruction
鲁东大学 LUDONG UNIVERSITY Pseudo Instruction-编译器将编译为ARM机器指令,与Directive Instuction不同。 ADR ADRL LDR NOP

21 ADR ADR-小范围地址读取指令 SYNAX ADR 寄存器号,表达式 地址相对于PC的偏移量,在-511B~512B的范围内。
鲁东大学 LUDONG UNIVERSITY ADR-小范围地址读取指令 SYNAX ADR 寄存器号,表达式 地址相对于PC的偏移量,在-511B~512B的范围内。 使用的标号必须是本段内定义的,不能使用导入的全局标号。 EXAMPLE: ADR r0,GotoThumb+1 BX r0 CODE16 GotoThumb ADD r0,r1

22 ADR伪指令通常会被汇编器翻译成一条语句 向前-sub rn,pc,#xxx ADRL会翻译成两条。
鲁东大学 LUDONG UNIVERSITY ADRL-中范围地址读取指令 可以加载的最大地址范围在±128KB的范围 与ADR相同,只能加载本段定义的标号地址 ADRL与ADR的区别 ADR伪指令通常会被汇编器翻译成一条语句 向前-sub rn,pc,#xxx 向后-add rn,pc,#xxx ADRL会翻译成两条。

23 ADR-ADRL区别说明 鲁东大学 LUDONG UNIVERSITY 8位补码,加边界对齐

24 LDR-用于加载32位的立即数/地址到目的寄存器 SYNTAX
ARM伪指令-操作伪指令(2) 鲁东大学 LUDONG UNIVERSITY LDR-用于加载32位的立即数/地址到目的寄存器 SYNTAX LDR 寄存器号,=立即数/地址标号表达式 EXAMPLE LDR r0,=0x LDR r0,=GotoThumb+10 区别:LDR r0,[r1] NOP-空操作,用于延时和预留存储空间


Download ppt "College of Computer Science & Technology"

Similar presentations


Ads by Google