简体   繁体   English

如何在 ARM aarch64 GCC 内联汇编中使用 32 位 w 寄存器?

[英]How to use 32-bit w registers in ARM aarch64 GCC inline assembly?

I can use 64-bit registers for example as in:我可以使用 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);
}

which compiles and disassembles with:它编译和反汇编:

aarch64-linux-gnu-gcc -ggdb3 -o main.out main.c
gdb-multiarch -batch -ex 'disassemble/rs main' main.out

to a 64-bit register as expected:按预期到 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]

How to use 32-bit registers such as w0 instead?如何改用 w0 等 32 位寄存器?

Tested on Ubuntu 18.04, GCC 7.4.0.在 Ubuntu 18.04、GCC 7.4.0 上测试。

It can be done by adding the w in front of the % , eg:可以通过在%前面添加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);
}

which now disassembles to the desired 32-bit version:现在反汇编为所需的 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]

This could have been somewhat guessed from: http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.100067_0612_00_en/qjl1517569411293.html since the ARM compiler 6 is LLVM based, and LLVM syntax is mostly GCC based.这可能有点猜测: http : //infocenter.arm.com/help/index.jsp? topic=/ com.arm.doc.100067_0612_00_en/qjl1517569411293.html因为 ARM 编译器 6 基于 LLVM 和 LLVM 语法主要基于 GCC。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 C汇编中的变量用法,如何在arm aarch64中选择32位操作数 - C variable usage in assembly, how to choose 32bit operands in arm aarch64 在GCC中使用内联汇编从32位IMUL返回64位结果 - Returning a 64-bit result from a 32-bit IMUL with inline assembly in GCC 用于32位字旋转的ARM内联汇编 - ARM inline assembly for 32-bit word rotate 不能强制在GCC内联汇编中使用64位寄存器 - Can't force the use of 64-bit registers in GCC inline assembly 如何在 32 位 kernel 中静态定义低 16 位地址的 IDT(使用 gcc 内联汇编) - How to statically define an IDT with low-16 addresses in a 32-bit kernel (with gcc inline assembly) 如何以及何时在AArch64上使用-mbig-endian gcc选项? - How and when to use -mbig-endian gcc option on AArch64? GCC; arm64; aarch64; 无法识别的命令行选项&#39;-mfpu = neon&#39; - gcc; arm64; aarch64; unrecognized command line option '-mfpu=neon' %w操作数上的ARM GCC内联汇编错误 - ARM GCC inline assembly error on %w operand 当被除数为 64 位且商为 32 位时,如何使 gcc 或 clang 使用 64 位/32 位除法而不是 128 位/64 位除法? - How to make gcc or clang use 64-bit/32-bit division instead of 128-bit/64-bit division when the dividend is 64-bit and the quotient is 32-bit? GCC无法从具有内联汇编的函数生成32位代码 - GCC fails to generate 32-bit code from a function with inline assembly
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM