flat assembler
Message board for the users of flat assembler.

Index > Non-x86 architectures > align directive

Author
Thread Post new topic Reply to topic
pepe



Joined: 26 Feb 2015
Posts: 19
pepe 26 Jun 2024, 17:56
Hello,

i used align directive to align data so far, but for my current code i need to align a branch instruction to return from a thumb exception handler.
Code:
thumb
...
align 4
BX PC
code32
align 4
movs PC,LR

    


This does not work because align puts 0xFF bytes into code instead of allowing to put 0x00 which would create MOVS r0,r0 as a NOP instruction (i know it is not a real NOP coz it may change flags, but it doesn't usually matter).
fasm doc says:
Quote:
The align directive fills the bytes that had to be skipped to perform the alignment with the nop instructions

FF FF is undefined instruction, so it is not very useful to insert into code Smile

I can circumvent this by a conditional but using 0 for alignment bytes would make the code look better...
Post 26 Jun 2024, 17:56
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20205
Location: In your JS exploiting you and your system
revolution 26 Jun 2024, 20:15
The fasmarm doc has this to say
Quote:
v1.08 2006-Jun-09 - Alignment bytes changed to 0xff to facilitate faster FLASH ROM updates


Edited out some bad analysis, sorry I was mistaken.
Post 26 Jun 2024, 20:15
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20205
Location: In your JS exploiting you and your system
revolution 26 Jun 2024, 22:24
Code:
echo "thumb
...
dh ($ and 2) shr 1 dup 0xbf00 
BX PC
code32
align 4
movs PC,LR"    
0xbf00 is the v6M nop. If your CPUs don't support it then 0x46c0 (cpy r8,r8) can be used instead. 0x46c0 was the suggested way to get a nop in ARM, until 6M introduced the true nops.
Post 26 Jun 2024, 22:24
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20205
Location: In your JS exploiting you and your system
revolution 27 Jun 2024, 00:00
I think using times may be better.
Code:
times ($ and 2) shr 1 nop    
Then you get the native nop for the selected processor.
Post 27 Jun 2024, 00: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-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.