mov: move

sub: subtract

cmp: compare

cmpls: ls--->lower or same, le--->less or equal, hi--->higher

ldr: load register

lsl: logical shift left

str: store register

b: branch

bl: branch label, change pc

bne: branch not equal

beq: branch equal

blt: branch less than

push {r4, r5} : store r4, r5 to stack

pop {r4, r5}: restore r4, r5 from stack

ldm: load multiple

stm: store multiple

and:

ldrd r0, r1, [r2, #4] : load 8 bytes from r2 + 4, and high 4 bytes stored in r0,  lower in r1

.align 2:  2 * 2 = 4, the ldr instruction we used to read memory only works at addresses that are multiples of 4

tst : compares two numbers by computing the logical and operation of the numbers, and then comparing the result with 0

strh reg,[dest]: stores the low half word number in reg at the address given by dest.

alias .req: reg sets alias to mean the register reg.

.unreq alias: removes the alias alias.

teq reg,#val: checks if the number in reg is equal to val.

========================================

Table 1.1 ARM ABI register usage
Register Brief Preserved Rules
r0 Argument and result No r0 and r1 are used for passing the first two arguments to functions, and returning the results of functions. If a function does not use them for a return value, they can take any value after a function.
r1 Argument and result No
r2 Argument No r2 and r3 are used for passing the second two arguments to functions. There values after a function is called can be anything.
r3 Argument No
r4 General purpose Yes r4 to r12 are used for working values, and their value after a function is called must be the same as before.
r5 General purpose Yes
r6 General purpose Yes
r7 General purpose Yes
r8 General purpose Yes
r9 General purpose Yes
r10 General purpose Yes
r11 General purpose Yes
r12 General purpose Yes
lr Return address No lr is the address to branch back to when a function is finished, but this does have to contain the same address after the function has finished.
sp Stack pointer Yes

sp is the stack pointer, described below. Its value must be the same after the function has finished.

========================================

movw 与 movt 指令

movw 与 movt 一般结合使用,用来往寄存器中加载一个 32 bit value。

环境:xcode 4.6.2,iPad 2, lldb

代码:

void ArmTest() {

asm (

"movw    r1, #0xF8C4\n\t" // 1

"movt    r1, #0x40\n\t" // 2

"mov     r0, r0"

);

}

在函数的开始部分设置断点,

然后读取 r1 寄存器的值(register read r1):r1 = 0x00000000

使用 ni 调试指令来继续执行一条指令,读取 r1 寄存器的值:r1 = 0x0000f8c4

继续单指令执行,读取寄存器值:r1 = 0x0040f8c4

可以得到结论:movw 将值加载到寄存器的低 16 位,movt 加载到高 16 位,合起来加载一个 32 bit value。

========================================

	Register  	Alt. Name  	Usage
r0 a1 First function argument Integer function result Scratch register
r1 a2 Second function argument Scratch register
r2 a3 Third function argument Scratch register
r3 a4 Fourth function argument Scratch register r4 v1 Register variable
r5 v2 Register variable
r6 v3 Register variable
r7 v4 Register variable
r8 v5 Register variable
r9 v6
rfp Register variable Real frame pointer r10 sl Stack limit
r11 fp Argument pointer
r12 ip Temporary workspace
r13 sp Stack pointer
r14 lr Link register Workspace
r15 pc Program counter

========================================

movs 说明

movs r3, #0

cpsr           {

0x30,

n = 0x0,

z = 0x0,

c = 0x0,

v = 0x0,

q = 0x0,

j = 0x0,

ge = 0x0,

e = 0x0,

a = 0x0,

i = 0x0,

f = 0x0,

t = 0x1,

mode = 0x10

}

执行后:

cpsr           {

0x40000030,

n = 0x0,

z = 0x1,

c = 0x0,

v = 0x0,

q = 0x0,

j = 0x0,

ge = 0x0,

e = 0x0,

a = 0x0,

i = 0x0,

f = 0x0,

t = 0x1,

mode = 0x10

}

总之,movs 在 mov 的功能基础上影响标志位(zero位)。

=============================

bic 指令

bic Rd,  Rn, Oprand2

BIC(位清除)指令对 Rn 中的值 和 Operand2 值的反码按位进行逻辑“与”运算。

BIC 是 逻辑”与非” 指令, 实现的 Bit Clear的功能

举例:

BIC     R0,   R0  , #0xF0000000

#将 R0  高4位清零

BIC    R1,  R1,   #0x0F

#将R1   低4位清0

RSB 反向减法

Rn, Operand2

RSB(反向减法)指令可从 Operand2 中的值减去 Rn 中的值。

这是很有用的,因为有了该指令,Operand2 的选项范围就会更大。

例如:

RSB r4, r4, #1280

从1280中减去 R4

RSB R4, R0, #0×46

从0×46 中 减去 R0, 放入R4

===================================

STM 与 LDM

STM和LDM的主要用途是现场保护、数据复制、参数传递等,其模式有8种,如下:

注:前面4种用于数据块的传输,后面4种用于堆栈操作

(1)IA  每次传送后地址加4

(2)IB  每次传送前地址加4

(3)DA  每次传送后地址减4

(4)DB  每次传送前地址减4

(5)FD  满递减堆栈

(6)FA  满递增堆栈

(7)ED  空递减堆栈

(8)EA  空递增堆栈

下面的讲述对于空递减堆栈和空递增堆栈同样适用.

在堆栈操作时,经常错误以为使用STMFD满递减将寄存器压入堆栈后,在弹出数据的时候应该使用LDMFA。

但是FD和FA仅用于指示目前操作的堆栈是何种模式(堆栈共有四种模式),FD指明目前的堆栈是满递减堆栈,

则数据入栈时的指令为STMFD,那么数据出栈时的指令对应的为LDMFD,而不是LDMFA。

我们可以这样认为STMFD等价于STMDB,LDMFD等价于STMIA

那么,数据传输的顺序和数据入栈的顺序又是如何呢

先来看STMFD SP!,{R1-R3}  执行的结果图(操作之后SP指向SP')

SP-------> |R3|

|R2|

SP'------>|R1|

那么STMFD SP!,{R3,R2,R1}执行后的堆栈顺序是不是刚好和上面的堆栈顺序相反,实际情况时这两个指令执行后的堆栈数据顺序一样,因为ARM编译器会自动将STMFD SP!,{R3,R2,R1}转换为STMFD SP!,{R0-R3}指令,也就是说,ARM编译器默认高寄存器优先存入堆栈。即便你在指令STMFD SP!,{R3,R2,R1}中刻意“安排”了寄存器入栈顺序,而在编译时编译器又重新做了处理,打乱了你期望的数据入栈顺序。

同理STMDB R0!,{R1-R3}和STMDB R0!,{R3,R2,R1}指令执行后数据在堆栈中的顺序完全一致。

STMFD SP!,{R1-R3}指令对应的出栈指令是LDMFD SP!,{R1-R3}(R1,R2,R3的顺序任意)

===================================

CBZ & CBNZ

比较,为零则跳转;比较,为非零则跳转。

语法

CBZ Rn, label
CBNZ Rn, label

其中:

Rn

是存放操作数的寄存器。

label

是跳转目标。

用法

可以使用 CBZ 或 CBNZ 指令避免更改条件代码标记并减少指令数目。

除了不更改条件代码标记外,CBZ Rn, label 与下列指令序列功能相同:

    CMP     Rn, #0
BEQ label

除了不更改条件代码标记外,CBNZ Rn, label 与下列指令序列功能相同:

    CMP     Rn, #0
BNE label

限制

跳转目标必须在指令之后的 4 到 130 个字节之内。

===================================

IT             EQ      /* if the EQ condition is true, (T)hen execute the next instruction */

MOVEQ   r0, #1  /* note the redundant condition code, which needs to match the IT instruction */

------------------

ITE           EQ      /* if the EQ condition is true, (T)hen execute the next instruction (E)lse execute the instruction after it */

MOVEQ   r0, #1

MOVNE   r0, #0  /* note that the condition code must be inverted, since this is an "else" instruction */

===================================

ARM备忘的更多相关文章

  1. GIS部分理论知识备忘随笔

    文章版权由作者李晓晖和博客园共有,若转载请于明显处标明出处:http://www.cnblogs.com/naaoveGIS/ 1.高斯克吕格投影带换算 某坐标的经度为112度,其投影的6度带和3度带 ...

  2. python序列,字典备忘

    初识python备忘: 序列:列表,字符串,元组len(d),d[id],del d[id],data in d函数:cmp(x,y),len(seq),list(seq)根据字符串创建列表,max( ...

  3. Vi命令备忘

    备忘 Ctrl+u:向文件首翻半屏: Ctrl+d:向文件尾翻半屏: Ctrl+f:向文件尾翻一屏: Ctrl+b:向文件首翻一屏: Esc:从编辑模式切换到命令模式: ZZ:命令模式下保存当前文件所 ...

  4. ExtJs4常用配置方法备忘

    viewport布局常用属性 new Ext.Viewport({ layout: "border", renderTo: Ext.getBody(), defaults: { b ...

  5. [备忘] Automatically reset Windows Update components

    这两天遇到Windows 10的更新问题,官方有一个小工具,可以用来修复Windows Update的问题,备忘如下 https://support.microsoft.com/en-us/kb/97 ...

  6. ECMAScript 5(ES5)中bind方法简介备忘

    一直以来对和this有关的东西模糊不清,譬如call.apply等等.这次看到一个和bind有关的笔试题,故记此文以备忘. bind和call以及apply一样,都是可以改变上下文的this指向的.不 ...

  7. MFC通过txt查找文件并进行复制-备忘

    MFC基于对话框的Demo txt中每行一个23位的卡号. 文件夹中包含以卡号命名的图像文件.(fpt或者bmp文件) 要求遍历文件夹,找到txt中卡号所对应的图像文件,并复制出来. VC6.0写的. ...

  8. php 相关模块备忘

    在安装php的时候,不管是编译安装: ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc -- ...

  9. 『备忘』HttpWebRequest 在 POST 提交时, 标头(Headers)丢失原因

    近来研究 HttpWebRequest —— 辅助类完成时,POST JSON数据 总会 丢失标头(Headers). HttpWebRequest POST JSON数据,分如下几步: > 将 ...

随机推荐

  1. WebService返回DataTable问题

    今天做项目时,想在WebService中返回DataTable,在单位没成功,看网上有人说datable在.net1.1中是没有序列化的,不能直接在webservice中返回,可以返回dataset. ...

  2. sql server中的索引详情

    什么是索引 拿汉语字典的目录页(索引)打比方:正如汉语字典中的汉字按页存放一样,SQL Server中的数据记录也是按页存放的,每页容量一般为4K .为了加快查找的速度,汉语字(词)典一般都有按拼音. ...

  3. MSSQL Server 2008 数据库安装失败

    1.Reporting Services目录临时数据库文件存在 出现这种问题的原因,是由于以前安装的SQL Server2008文件并没有卸载或删除干净造成      解决的办法如下:      找到 ...

  4. 猫学习IOS(十五)UI以前的热的打砖块游戏

    猫分享.必须精品 材料代号地址:http://blog.csdn.net/u013357243/article/details/44814523 原文地址:viewmode=contents" ...

  5. sql server drop talbe 自动删除关联的外键 ,权限体系(一)

    if object_id('Proc_DropTableWithFK') is not null begin drop proc dbo.Proc_DropTableWithFK end GO ) a ...

  6. MVC EF 修改 封装类 通用泛型方法(一)

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.D ...

  7. linux cat

    cut是一个选取命令,就是将一段数据经过分析,取出我们想要的.一般来说,选取信息通常是针对“行”来进行分析的,并不是整篇信息分析的. (1)其语法格式为:cut  [-bn] [file] 或 cut ...

  8. The Swift Programming Language-官方教程精译Swift(9) 枚举-- --Enumerations

    枚举定义了一个通用类型的一组相关的值,使你可以在你的代码中以一个安全的方式来使用这些值.   如果你熟悉 C 语言,你就会知道,在 C 语言中枚举指定相关名称为一组整型值.Swift 中的枚举更加灵活 ...

  9. 通俗易懂地解决中文乱码问题(2) --- 分析解决Mysql插入移动端表情符报错 ‘incorrect string value: '\xF0...

    原文:[原创]通俗易懂地解决中文乱码问题(2) --- 分析解决Mysql插入移动端表情符报错 'incorrect string value: '\xF0... 这篇blog重点在解决问题,如果你对 ...

  10. MonkeyRunner源码分析之-谁动了我的截图?

    本文章的目的是通过分析monkeyrunner是如何实现截屏来作为一个例子尝试投石问路为下一篇文章做准备,往下一篇文章本人有意分析下monkeyrunner究竟是如何和目标测试机器通信的,所以最好的办 ...