Recent

Author Topic: [worked around]How to use adr instruction in AArch64?  (Read 1427 times)

pik33

  • Jr. Member
  • **
  • Posts: 78
[worked around]How to use adr instruction in AArch64?
« on: July 28, 2020, 10:15:27 am »
I tried to get an address of a label in Raspbian 64bit on RPi4 using Lazarus 2.10/fpc 3.3.1

Code: [Select]

function test:pointer;

label aaa;
var a:pointer;

begin

     asm
aaa: adr x1,aaa
     str x1,a
     end;

result:=a;

end;


and got "invalid reference syntax" compiler error in line labelled "aaa:"

What I did wrong?  How to use adr instruction here? In the standalone assembler as the syntax adr reg,label is ok. 
« Last Edit: July 28, 2020, 01:32:14 pm by pik33 »

pik33

  • Jr. Member
  • **
  • Posts: 78
Re: How to use adr instruction in AArch64?
« Reply #1 on: July 28, 2020, 12:04:30 pm »
Partially solved.

Syntax that works is is adr Xn,#imm

Incompatible with all A64 assembly manuals (use adr reg,label); compatible with the raw instruction code

The label position in code can be translated to #imm manually but it can be broken with changes in the code.
« Last Edit: July 28, 2020, 12:08:47 pm by pik33 »

PascalDragon

  • Hero Member
  • *****
  • Posts: 6356
  • Compiler Developer
Re: How to use adr instruction in AArch64?
« Reply #2 on: July 28, 2020, 01:10:36 pm »
I can't test it right now (I can test more once I'm at home in the evening), but the following might work (considering that I used similar code in the Rtti unit):

Code: Pascal  [Select][+][-]
  1. asm
  2. .LAddr:
  3.   adr x1, .LAddr
  4.   str x1, a
  5. end;

This is a local assembly-only label in contrast to a Pascal label.

pik33

  • Jr. Member
  • **
  • Posts: 78
Re: How to use adr instruction in AArch64?
« Reply #3 on: July 28, 2020, 01:21:20 pm »
I can't test it right now (I can test more once I'm at home in the evening), but the following might work (considering that I used similar code in the Rtti unit):

Code: Pascal  [Select][+][-]
  1. asm
  2. .LAddr:
  3.   adr x1, .LAddr
  4.   str x1, a
  5. end;

This is a local assembly-only label in contrast to a Pascal label.

This didn't work with the same error message.

 

TinyPortal © 2005-2018