digging a bit I see that the gen purpose registers are uint_32 which i think means 32-bit integer only
what needs to happen then (i think) is converting a fp number to uint_32 on storage and back again when I pop the register.
can anyone confirm that i'm on the right track? each register is 4 bytes so should be sufficient to hold an fp number (right?)
would not mind some pointers on effecting that...
digging a bit I see that the gen purpose registers are uint_32 which i think means 32-bit integer only
what needs to happen then (i think) is converting a fp number to uint_32 on storage and back again when I pop the register.
can anyone confirm that i'm on the right track? each register is 4 bytes so should be sufficient to hold an fp number (right?)
would not mind some pointers on effecting that...
You can read set_float from right to left as get the address of the float value (&value), cast that to be an address of an int value (uint32_t*), and then read the value of the int at that address (*). So instead of casting the value itself (which would do a conversion), you cast a pointer to it.
...assuming i haven't made a mistake!
Simon
Hi Gary,
I think you'd want to do something like:
<<code>>
#include "mbed.h"
void set_float(float value) {
LPC_RTC->GPREG0 = *((uint32_t*)&value);
}
float get_float() {
return *((float*)&(LPC_RTC->GPREG0));
}
int main() {
set_float(2.0);
float v = get_float();
}
<</code>>
You can read set_float from right to left as get the address of the float value (&value), cast that to be an address of an int value (uint32_t*), and then read the value of the int at that address (*). So instead of casting the value itself (which would do a conversion), you cast a pointer to it.
...assuming i haven't made a mistake!
Simon
TNX! works a charm. Still learning how the compiler manipulates memory (as you can tell...).
One last pesky question then. How to expand this to utilize all of the registers gpreg0-4 ?
gmb
Simon,
TNX! works a charm. Still learning how the compiler manipulates memory (as you can tell...).
One last pesky question then. How to expand this to utilize all of the registers gpreg0-4 ?
gmb
Important Information for this Arm website
This site uses cookies to store information on your computer.
By continuing to use our site, you consent to our cookies.
If you are not happy with the use of these cookies, please review our
Cookie Policy
to learn how they can be disabled.
By disabling cookies, some features of the site will not work.
Access Warning
You do not have the correct permissions to perform this operation.
can these be used to store floating point numbers between resets?
easily save integers but haven't discovered how to stash fp...