flat assembler
Message board for the users of flat assembler.

Index > Non-x86 architectures > [fasmarm] Automatic ITE blocks...

Author
Thread Post new topic Reply to topic
pepe



Joined: 26 Feb 2015
Posts: 19
pepe 26 Feb 2015, 14:55
Hello,

my purpose is to write small portions of code, as small as possible of course.
as i see FASMARM compiles the code OK, but it inserts ITT instructions for no obvious reason. with a longer code they appear pretty frequently.
Is there a way to avoid this behaviour?

Code:
Seg003:002E8002 05 4D                       LDR     R5, =pSomeFunction
seg003:002E8004 2C 68                       LDR     R4, [R5]
seg003:002E8006 E1 BF                       ITTTT AL
seg003:002E8008 A5 20                       MOV     R0, #0xA5 ; ''
seg003:002E800A A0 47                       BLX     R4
seg003:002E800C 1C 3D                       SUB     R5, #0x1C
seg003:002E800E 2C 68                       LDR     R4, [R5]
seg003:002E8010 A0 47                       BLX     R4
seg003:002E8010             ; ---------------------------------------------------------------------------
seg003:002E8012 FF                          DCB 0xFF
seg003:002E8013 FF                          DCB 0xFF
seg003:002E8014 74                          DCB 0x74 ; t
seg003:002E8015 00                          DCB    0
seg003:002E8016 10                          DCB 0x10
seg003:002E8017 00                          DCB    0
seg003:002E8018 90 00 10 00 off_2E8018      DCD pSomeFunction   ; DATA XREF: seg003:002E8002r    


Thanks,
pepe
Post 26 Feb 2015, 14:55
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20430
Location: In your JS exploiting you and your system
revolution 26 Feb 2015, 15:18
If you don't want IT instructions in THUMB mode than you can use the wide (.w) versions. But this will increase the code size. Note: that fasmarm only inserts IT instructions when it is forced to because of a condition code or if there is a saving in code size.

The presence of IT in the above example gives you a smaller code footprint than if the wide version of each instruction was used. The reason for the ITTTT AL is because there are no short 16-bit versions of the instructions you used. The 16-bit opcodes are very limited and many of the arithmetic instructions always update the flags so using an "ITTTT AL" wrapper instruction allows the following instructions to not set the flags. It is a trick used to get smaller code.
Post 26 Feb 2015, 15:18
View user's profile Send private message Visit poster's website Reply with quote
pepe



Joined: 26 Feb 2015
Posts: 19
pepe 26 Feb 2015, 16:11
Hey, thanks for the quick reply.

Now i seem to get it. So if i used MOVS and SUBS, the ITTTT AL could be avoided.

great idea, thanks for the explanation.

pepe
Post 26 Feb 2015, 16:11
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20430
Location: In your JS exploiting you and your system
revolution 26 Feb 2015, 16:15
pepe wrote:
Now i seem to get it. So if i used MOVS and SUBS, the ITTTT AL could be avoided.
Yes, that is basically it. And fasmarm can't do that for you because it doesn't know the state of the flags and whether it can change them.

Also note the existence and differences between UAL (THUMB) and pre-UAL (CODE16) modes. The pre-UAL is quite confusing with the removal of the 'S' in only some of the thumb instruction opcodes. I recommend not using pre-UAL opcodes unless you have old code you are supporting.
Post 26 Feb 2015, 16:15
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.