Forum Discussion
Altera_Forum
Honored Contributor
16 years agoWritting 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/W11 Replies
- Altera_Forum
Honored 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):
I don't know if there is a more elegant way to do it... --- Quote End --- Thanks a lot! This solved my problems toofloat 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