Shop OBEX P1 Docs P2 Docs Learn Events
.float directive in *.S files — Parallax Forums

.float directive in *.S files

altosackaltosack Posts: 132
edited 2015-03-17 04:44 in Propeller 1
This works:
#define SCK_PIN                 26
SCK_MASK                .long   1 << SCK_PIN

But this doesn't work...:
#define ADC_BITS                    12          // Don't include sign bit
#define VREF                        0.604
#define LSB                         VREF / ((1 << ADC_BITS) - 1)

#define S_BAT                       0.001       // 1 milli-Ohm Shunt

#define BATTERY_AMPS_SAMPLES_BITS   12

batteryAmpsScale        .float  LSB / S_BAT / (1 << BATTERY_AMPS_SAMPLES_BITS)

...so I have to do this:
batteryAmpsScale        .float  0.00003601

I'm using the propgcc that came with SimpleIDE 0.9.46 for linux (I don't use SimpleIDE). Does anyone know if this is fixed in the .float directive in newer propgcc versions, or if there is something I don't understand about the syntax ? It fails on the first '/' encountered and doesn't seem to support any arithmetic at all in the .float directive even though the exact same arithmetic works in the .long directive.

Any light anyone can shine on this would be very much appreciated.

Comments

  • ersmithersmith Posts: 6,053
    edited 2015-03-17 04:44
    Unfortunately the assembler only has very limited support for expressions, and then only integer ones. So it's just not possible. (Floating point is especially tricky because it's very difficult to ensure that the floating point calculations on the host that is doing the compile match what would be done on the target.)

    You could, though, put those constants in a C file: the C compiler is big and compilcated enough that it does implement floating point calculations. You'd have to arrange to link the C compiled output with the assembler output.
Sign In or Register to comment.