aarch64 arm - adr ldr 伪指令-汇编指令-汇编器-随记拾遗

 

1、我们些的汇编代码 head.S 是被 汇编软件处理的。所以,我们 .S  里面的内容怎么写,应该看  汇编软件 的指南。

gnu 汇编器  文档: https://sourceware.org/binutils/docs-2.38/as/index.html 

 

aarch64-下gnu as 可以识别的 ldr adr

https://sourceware.org/binutils/docs-2.38/as/AArch64-Opcodes.html#AArch64-Opcodes

 

GAS implements all the standard AArch64 opcodes. It also implements several pseudo opcodes, including several synthetic load instructions.

gnu as 可以 识别   ‘ARMv8 Instruction Set Overview’ 中列出的 所有标准汇编指令和下面的这个 伪指令
LDR =
  ldr <register> , =<expression>

The constant expression will be placed into the nearest literal pool (if it not already there) and a PC-relative LDR instruction will be generated.

For more information on the AArch64 instruction set and assembly language notation, see ‘ARMv8 Instruction Set Overview’ available at http://infocenter.arm.com.

所有的aarch64 标准指令 参见:  ‘ARMv8 Instruction Set Overview’ available at http://infocenter.arm.com.

 

 

arm 下gnu as 可以识别的 ldr adr

https://sourceware.org/binutils/docs-2.38/as/ARM-Opcodes.html#ARM-Opcodes 

as implements all the standard ARM opcodes. It also implements several pseudo opcodes, including several synthetic load instructions.

as 可以识别 所有的 标准的 ARM 汇编指令( ARM Software Development Toolkit Reference Manual,  中列出的)和 下面这 4 个伪操作(伪指令)

NOP
  nop

This pseudo op will always evaluate to a legal ARM instruction that does nothing. Currently it will evaluate to MOV r0, r0.

LDR
  ldr <register> , = <expression>

If expression evaluates to a numeric constant then a MOV or MVN instruction will be used in place of the LDR instruction, if the constant can be generated by either of these instructions. Otherwise the constant will be placed into the nearest literal pool (if it not already there) and a PC relative LDR instruction will be generated.

ADR
  adr <register> <label>

This instruction will load the address of label into the indicated register. The instruction will evaluate to a PC relative ADD or SUB instruction depending upon where the label is located. If the label is out of range, or if it is not defined in the same file (and section) as the ADR instruction, then an error will be generated. This instruction will not make use of the literal pool.

If label is a thumb function symbol, and thumb interworking has been enabled via the -mthumb-interwork option then the bottom bit of the value stored into register will be set. This allows the following sequence to work as expected:

  adr     r0, thumb_function
  blx     r0
ADRL
  adrl <register> <label>

This instruction will load the address of label into the indicated register. The instruction will evaluate to one or two PC relative ADD or SUB instructions depending upon where the label is located. If a second instruction is not needed a NOP instruction will be generated in its place, so that this instruction is always 8 bytes long.

If the label is out of range, or if it is not defined in the same file (and section) as the ADRL instruction, then an error will be generated. This instruction will not make use of the literal pool.

If label is a thumb function symbol, and thumb interworking has been enabled via the -mthumb-interwork option then the bottom bit of the value stored into register will be set.

For information on the ARM or Thumb instruction sets, see ARM Software Development Toolkit Reference Manual, Advanced RISC Machines Ltd.

更多的,汇编使用的 arm 指令和 thumb 指令,参见 ARM Software Development Toolkit Reference Manual

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

aarch64 里面,没有 ADRL 伪指令, 使用就会 报错。

zhiwei@zhiwei-pc:~/work/qemu-aarch64/examples$ aarch64-linux-gnu-gcc -nostdlib -nodefaultlibs -o head.elf head.S
head.S: Assembler messages:
head.S:8: Error: unknown mnemonic `adrl' -- `adrl x3,loop'

LDR 指令

标准指令是加载    内存中的数据    到   寄存器。

有三种形式:

第一种形式

a. xn 寄存器作基地址,立即数作偏移:

a.1   post index. 先加载,后修改 xn 寄存器的值

  ldr <xt> [<xn>], #<simm>

a.2  pre index 先修改 xn 寄存器的值,后 加载。

  ldr <xt> [<xn>, #<simm> ]!

a.3  unsigned offset 无符号偏移,加载后,不修改 xn 寄存器的值。

  ldr <xt> [<xn> {, #<pimm> }]

第二种形式:

b. label

   ldr <xt> label

第三种形式:

c. 寄存器

LDR <Xt>, [<Xn>, (<Xm>){, <extend> {<amount>}}]

 

伪指令形式-加载立即数到寄存器

ldr <register> , = <expression>

  将 常量 放在   最近处的 literal pool  里面,然后  使用一条 ldr 语句 从 literal pool 里面加载 常量。 

 

adr 指令

arm 中是伪指令

adr <register> <label>

aarch64 中是  标准指令

    ADR <Xd>, <label>

 

ADRP 指令

AArch64 中的 标准指令

      ADRP <Xd>, <label>

 

posted @ 2022-03-05 16:40  张志伟122  阅读(1159)  评论(0编辑  收藏  举报