Nios® V/II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® V/II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++
12612 Discussions

Reading from an 8 Bit Component

Altera_Forum
Honored Contributor II
1,645 Views

Hi, 

 

I connected the Nios to an 8 bit custom component. When I read from a register which contains a 1 as the most significant bit, i.e. all values from 0x80 to 0xFF, the remaining 24 bits get filled up with 1's.  

 

For example reading the value 0x70 residing in one of the component's registers gives the value 0x00000070 to the variable I'm saving it to. But reading 0x80 gives the value 0xFFFFFF80. 

 

So I guess the values are treated as signed values, which would explain why it fills the remaining bits with 1's.  

 

But how can I prevent that? 

 

Thanks in advance
0 Kudos
2 Replies
Altera_Forum
Honored Contributor II
289 Views

Hi stic, 

 

> For example reading the value 0x70 residing in one of the component's registers gives the 

> value 0x00000070 to the variable I'm saving it to. But reading 0x80 gives the value 0xFFFFFF80. 

 

If you're reading an 8-bit unsigned value, it's a good idea to store it as an 8-bit unsigned 

variable ;-) 

 

unsigned char foo = <<whatever>> 

 

Regards, 

--Scott
0 Kudos
Altera_Forum
Honored Contributor II
289 Views

 

--- Quote Start ---  

originally posted by smcnutt@Jan 19 2007, 09:51 AM 

if you&#39;re reading an 8-bit unsigned value, it&#39;s a good idea to store it as an 8-bit unsigned 

variable ;-) 

<div align='right'><{post_snapback}> (index.php?act=findpost&pid=20715) 

--- quote end ---  

 

--- Quote End ---  

 

 

Yes, indeed it is a very good idea to use unsigned char...  

I didn&#39;t think of this before. 

 

Thanks a lot, Scott
0 Kudos
Reply