satyria
Posts: 42
Joined: Sun May 12, 2013 5:41 pm

Change code from FASMARM assembler to GAS

Wed Sep 30, 2020 11:42 am

I'm currently trying to change a code that was written for FASMARM to Gnu AS.
The following code is written as a macro in FASMARM:

Code: Select all

macro imm32 reg,immediate {
  mov reg,(immediate) and $FF
  orr reg,(immediate) and $FF00
  orr reg,(immediate) and $FF0000
  orr reg,(immediate) and $FF000000
}
My change resulted in this code:

Code: Select all

.macro imm32 reg,immediate 
  mov \reg,\immediate and $FF
  orr \reg,\immediate and $FF00
  orr \reg,\immediate and $FF0000
  orr \reg,\immediate and $FF000000
.endm
Now when I use this macro with the following code, I get error messages.
Code:

Code: Select all

imm32 r0,#FB_STRUCT + MAIL_TAGS
Error messages:

Code: Select all

main.s:25: Error: garbage following instruction -- `mov r0,#FB_STRUCT+MAIL_TAGS and $FF'
main.s:25: Error: garbage following instruction -- `orr r0,#FB_STRUCT+MAIL_TAGS and $FF00'
main.s:25: Error: garbage following instruction -- `orr r0,#FB_STRUCT+MAIL_TAGS and $FF0000'
main.s:25: Error: garbage following instruction -- `orr r0,#FB_STRUCT+MAIL_TAGS and $FF000000'
What should the macro look like correctly?
Greetings, Matthias

hippy
Posts: 8545
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: Change code from FASMARM assembler to GAS

Wed Sep 30, 2020 12:12 pm

This is what I am using ....

Code: Select all

.macro          num32   reg,opr
                mov     \reg,#(\opr) & 0xFF000000
                orr     \reg,#(\opr) & 0x00FF0000
                orr     \reg,#(\opr) & 0x0000FF00
                orr     \reg,#(\opr) & 0x000000FF
.endm
Putting the 'opr' within brackets ensures precedence is kept when it is invoked with an expression. And I don't think '$' is accepted as a hexadecimal prefix; use '0x' instead.

User avatar
jahboater
Posts: 6289
Joined: Wed Feb 04, 2015 6:38 pm
Location: Wonderful West Dorset

Re: Change code from FASMARM assembler to GAS

Wed Sep 30, 2020 12:15 pm

Perhaps use movw and movt instead of all the orr's ? (16-bit immediates)
At least:

Code: Select all

movw \reg,#(\opr) & 0x0000FFFF
should save one insn.
similarly mov and movk for A64

The A72 CPU is starting to merge these operations.
Pi4 8GB running PIOS64 Lite

satyria
Posts: 42
Joined: Sun May 12, 2013 5:41 pm

Re: Change code from FASMARM assembler to GAS

Wed Sep 30, 2020 12:50 pm

Great, it worked. But now I get a new error message:

Code: Select all

main.s:25: Error: invalid operands (.text and *UND* sections) for `+'
The code is:

Code: Select all

imm32 r0,FB_STRUCT + MAIL_TAGS
Greetings, Matthias

Return to “Bare metal, Assembly language”