我可以使用64位寄存器,例如:
#include <assert.h>
#include <inttypes.h>
int main(void) {
uint64_t io = 1;
__asm__ (
"add %[io], %[io], 1;"
: [io] "+r" (io)
:
:
);
assert(io == 2);
}
它使用以下命令编译和反汇编:
aarch64-linux-gnu-gcc -ggdb3 -o main.out main.c
gdb-multiarch -batch -ex 'disassemble/rs main' main.out
与预期的64位寄存器相同:
6 __asm__ (
0x0000000000000744 <+16>: a0 0f 40 f9 ldr x0, [x29, #24]
0x0000000000000748 <+20>: 00 04 00 91 add x0, x0, #0x1
0x000000000000074c <+24>: a0 0f 00 f9 str x0, [x29, #24]
如何使用32位寄存器,如w0?
在Ubuntu 18.04,GCC 7.4.0上测试。
发布于 2019-12-18 23:28:25
可以通过在%
前面添加w
来实现,例如:
#include <assert.h>
#include <inttypes.h>
int main(void) {
uint32_t io = 1;
__asm__ (
"add %w[io], %w[io], 1;"
: [io] "+r" (io)
:
:
);
assert(io == 2);
}
现在可以反汇编成所需的32位版本:
6 __asm__ (
0x0000000000000744 <+16>: a0 1f 40 b9 ldr w0, [x29, #28]
0x0000000000000748 <+20>: 00 04 00 11 add w0, w0, #0x1
0x000000000000074c <+24>: a0 1f 00 b9 str w0, [x29, #28]
这在某种程度上可以从http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.100067_0612_00_en/qjl1517569411293.html中猜到,因为ARM编译器6是基于LLVM的,而LLVM语法主要是基于GCC的。
https://stackoverflow.com/questions/59395244
复制相似问题