str指令作用
str r0,[r1] str作用是把左边r0寄存器里的值,存入到 右边[r1]内存地址中
str x0,[x1,#0x10] //x->[x1+0x10]
#str 在函数中的作用 oc代码调用int fn1(int a,int *b);
int a = 1;
int b = 10;
int result = fn1(a,&b);
_fn1:
str x0,[x1]//把fn1(参数1,参数2) x0里是参数1,把x0的值存入到 x1(参数2的指向的内存地址里)
ret
下面是lldb调试结果:, x0的值赋值给了x1地址里的内存. x1地址里的值也变成了x0的值:1
(lldb) re read x1
x1 = 0x000000016af09418
(lldb) x 0x000000016af09418
0x16af09418: 0a 00 00 00 01 00 00 00 80 28 5e 80 02 00 00 00 .........(^.....
0x16af09428: 60 7a 0c 83 02 00 00 00 ec 1d de ef 01 00 00 00 `z..............
(lldb) re read x0
x0 = 0x0000000000000001
(lldb) si
(lldb) x 0x000000016af09418
0x16af09418: 01 00 00 00 00 00 00 00 80 28 5e 80 02 00 00 00 .........(^.....
0x16af09428: 60 7a 0c 83 02 00 00 00 ec 1d de ef 01 00 00 00 `z..............
str和 stur的区别是,stur右边的立即数是负数,u代表立即数是负数
跟ldr和ldur一样,u都是负数
str x0,[x1,#0x10] //正数 x0->[x1+0x10]
stur x0,[x1,#-0x10] //负数 x0->[x1-0x10]
stp p是pair,把一对寄存器写入到右边内存
stp w0,w1,[x2] //把w0和 w1里面的值,写入到右边内存,[x2]中,w0在左边,w1在右边
在oc中的调用 fn2的声明
int fn2(int a,int b,int *c);
调用
int c = 1;
int d = 2;
int e = 0;
result = fn2(c, d,&e);
NSLog(@"result=%d",result);
汇编函数定义
_fn2:
//w0 存储参数1,w1存储参数2.因为w0和w1共同组成x0,第三个参数向后延续一个寄存器,所以参数3存入x1中
stp w0,w1,[x2] //把w0和 w1里面的值,写入到右边内存,[x2]中,w0在左边,w1在右边
mov x0,x2//把x2的值存入返回值x0中
ret
调试结果
(lldb) re read x2
x2 = 0x000000016fd9540c
(lldb) x 0x000000016fd9540c
0x16fd9540c: 00 00 00 00 02 00 00 00 01 00 00 00 0a 00 00 00 ................
0x16fd9541c: 01 00 00 00 c0 e4 6d 83 02 00 00 00 00 88 3e 80 ......m.......>.
(lldb) re read w0
w0 = 0x00000001
(lldb) re read w1
w1 = 0x00000002
(lldb) si
(lldb) x 0x000000016fd9540c
0x16fd9540c: 01 00 00 00 02 00 00 00 01 00 00 00 0a 00 00 00 ................
0x16fd9541c: 01 00 00 00 c0 e4 6d 83 02 00 00 00 00 88 3e 80 ......m.......>.
(lldb) si
(lldb) re read x0
x0 = 0x000000016fd9540c
这个x0就是返回值,赋值给int类型是取走后8位,就是 0x6fd9540c,转换成10进制就是1876513804 打印结果:
result=1876513804
|