flat assembler
Message board for the users of flat assembler.

Index > Non-x86 architectures > [fasmarm] Syntax for far address loading

Author
Thread Post new topic Reply to topic
Chris Leslie



Joined: 19 Oct 2024
Posts: 7
Location: Canberra
Chris Leslie 27 Nov 2025, 20:11
In fasmarm elf64 how can i load a register with a far label address? Adr x0, mylabel won't look far enough and ldr x0,=mylabel is not valid.
Post 27 Nov 2025, 20:11
View user's profile Send private message Send e-mail Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20785
Location: In your JS exploiting you and your system
revolution 27 Nov 2025, 20:26
The address needs to be broken down into parts.
Code:
format elf64 executable at 0x123456789a0
processor cpu64_v8
my_label:
        movk    w1,(my_label shr 00) and 0xFFFF
        movk    w1,(my_label shr 16) and 0xFFFF,lsl 16
        movk    x1,(my_label shr 32) and 0xFFFF,lsl 32
        movk    x1,(my_label shr 48) and 0xFFFF,lsl 48    
Code:
00000078: 72914301 V8     movk  w1,0x8a18
0000007c: 72a8ace1 V8     movk  w1,0x4567,lsl 16
00000080: f2c02461 V8     movk  x1,0x123,lsl 32
00000084: f2e00001 V8     movk  x1,0x0,lsl 48    
Post 27 Nov 2025, 20:26
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8483
Location: Kraków, Poland
Tomasz Grysztar 27 Nov 2025, 20:28
Perhaps it's the ADRP that you're looking for? I have the technique demonstrated at the very end of chapter 1.6 of my formats tutorial.
Post 27 Nov 2025, 20:28
View user's profile Send private message Visit poster's website Reply with quote
Chris Leslie



Joined: 19 Oct 2024
Posts: 7
Location: Canberra
Chris Leslie 27 Nov 2025, 20:47
Yes, I need to load the page address with adrp and then add the offset of my label, but getting a syntax that passes is the problem. I will try to adapt the technique at the end of chapter 1.6.
Post 27 Nov 2025, 20:47
View user's profile Send private message Send e-mail Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20785
Location: In your JS exploiting you and your system
revolution 27 Nov 2025, 22:33
For relative labels this can be used:
Code:
format elf64 executable at 0x123456789a0
processor cpu64_v8
my_label:
        adrp    x0,far_label
        add     x0,x0,far_label and 0xfff
rb 1 shl 25
far_label:    
Code:
00000078: 90010000 V8     adrp  x0,0x002000000
0000007c: 91288000 V8     add   x0,x0,0xa20    
Post 27 Nov 2025, 22:33
View user's profile Send private message Visit poster's website Reply with quote
Chris Leslie



Joined: 19 Oct 2024
Posts: 7
Location: Canberra
Chris Leslie 28 Nov 2025, 10:20
Thanks revolution. What is the purpose of at 0x123456789a0?
And, what does rb 1 shl 25 do in that position?
Post 28 Nov 2025, 10:20
View user's profile Send private message Send e-mail Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20785
Location: In your JS exploiting you and your system
revolution 28 Nov 2025, 14:00
0x123456789a0 is just an example to demonstrate a "large" address that can't be encoded in one instruction.

rb 1 shl 25 is just an example to skip a large amount of space to create a "far" label that can't be reached in one instruction.
Post 28 Nov 2025, 14:00
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.