Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
15 years ago

Writting floating point numbers using IOWR IORD

Hi,

I'm trying to read a custom register which has a 32 bit floating point value, from the NIOS in the c-code using the Macro IORD(base,offset).

If I assign this to a variable defined as float and Add it with 2.

And write the result into another custom register using IOWR Macro.

I'm not getting equivalent IEEE-754 value in the register.

Can anybody suggest what might be the problem?

Code is as below:

float x,v;

x= IORD(IOREG_BASE,0); // Reading from the register1 defined in H/W

v= x+2;

IOWR(IOREG_BASE,1,v); // Writing to register2 defined in H/W

11 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    --- Quote Start ---

    In my opinion the compiler sees the IORD result as an integer, and will cast it to a float value. I think the only way you could get around this is by using pointers and changing the pointer type. Something like (not tested):
    float x,v;
    *((unsigned int*)&x)= IORD(IOREG_BASE,0); // Reading from the register1 defined in H/W
    v= x+2;
    IOWR(IOREG_BASE,1,*((unsigned int*)&v)); // Writing to register2 defined in H/W

    I don't know if there is a more elegant way to do it...

    --- Quote End ---

    Thanks a lot! This solved my problems too