3

I'm programming in ARM assembly in DS-5 5.28, targetting cortex-a8 with floating point and Neon.

When expressing constants with EQU, like

M EQU 5

then I can use the constant in the rest of the program, in particular when allocating constants in data memory like e.g:

mydata  DCD  M

Now, if I want to allocate a floating point constant as 32-bit binary, I can do:

myfloat  DCFS  5

or indifferently:

myfloat  DCFS  5.0

But the following gives syntax error:

myfloat  DCFS  M

I've tried all sort of tricks like DCFS (M+0.0) or M EQU 5.0, but nothing is accepted by the assembler, and I can't find directives to cast constants, and not even an Arm forum that seems suitable. Nor I'd like to hard-code constants (that may change) more than once in the code.

EDIT 1

I've tried with macros, same error (A1194E: Bad floating-point number):

    MACRO
$label  FP_CONSTANT  $value
$label  DCFS    $value
    MEND

; use:
myfloat  FP_CONSTANT  M

I would like to check if I wrote it correctly by disassembling the result, but compilation fails so there's no object to disassemble.

m.alessandrini
  • 317
  • 2
  • 9
  • Yeah, I see. That's not what I mean with “use a macro,” but it seems like the assembler doesn't support the kind of macros I was thinking about anyway. – fuz Jan 26 '18 at 13:10
  • If you mean C-like macros, that's what I was actually looking for, but I did not found anything [see here for example](https://developer.arm.com/products/software-development-tools/compilers/arm-compiler-5/docs/dui0473/latest/directives-reference) – m.alessandrini Jan 26 '18 at 14:12
  • For GNU GAS, I would recommend using the C preprocessor for macros, since GAS preprocessing is just too weak. Related: https://stackoverflow.com/questions/6514537/how-do-i-specify-immediate-floating-point-numbers-with-inline-assembly/52906126#52906126 but `.equ asdf, #1.5` refuses to work for that syntax and any variant I've tried on AS 2.31. – Ciro Santilli Oct 20 '18 at 15:36

1 Answers1

1

The EQU directive defines a symbol to take a specific value. Symbol values are addresses which are in turn integers. You can't give a symbol a floating point number as a value.

As an alternative, read the manual of your assembler. Most assemblers have the capability to define macros which should allow you to give a symbolic name to a floating point constant by defining it as a macro.

fuz
  • 88,405
  • 25
  • 200
  • 352
  • I've read the manual deeply, I think I don't deserve "RTFM" replies. I did not think of macros, I'll check but I'm a little bit skeptic because the problem seems you cannot define a floating point constant from an integer one. Something like C's #define would be needed, more like a low-level textual substitution. – m.alessandrini Jan 26 '18 at 11:47
  • @m.alessandrini Macros are essentially that low-level textual substitution. I referred you to the manual because I am not familiar with your assembler, so it's probably easier if you look up how to use macros on your own then have me guess what the syntax is. – fuz Jan 26 '18 at 11:54
  • Ok thanks, sorry for the misunderstanding. Unfortunately I've tried with macros (useful knowledge anyway) but it raises the same error after macro expansion: Bad floating-point number – m.alessandrini Jan 26 '18 at 12:14
  • @m.alessandrini Could you add the code with macros to your question so I can understand what exactly you wrote? – fuz Jan 26 '18 at 12:51