【发布时间】:2018-12-20 21:00:03
【问题描述】:
我正在查看这个函数的汇编输出:
extern void write(char * buff);
void test(int x)
{
// copy "EXAMPLE\0\0\0\0\0..."
char buff[16] = "EXAMPLE";
// set byte 10 to '0'+x
buff[10] = '0' + x;
// write
write(buff);
}
它看起来像like this:
test:
push {r4, lr}
ldr r2, .L4
mov r3, r0
ldm r2, {r0, r1}
sub sp, sp, #16
mov r2, sp
adds r3, r3, #48
stm r2, {r0, r1}
movs r4, #0
mov r0, r2
strd r4, r4, [sp, #8]
strb r3, [sp, #10]
bl write
add sp, sp, #16
pop {r4, pc}
.L4:
.word .LANCHOR0
.cfi_endproc
.LFE0:
.size test, .-test
.section .rodata
.align 2
.set .LANCHOR0,. + 0
.ascii "EXAMPLE\000"
.space 8
.text
我完全不知道从.L4 复制到堆栈发生在哪里?
我看到堆栈指针移动了 16B,并且我看到 '0'+x 的 adds 指令,但是哪个指令复制了数据?
对不起,新手问题,谢谢!
【问题讨论】:
标签: c assembly arm array-initialization