- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
As suggested by forumer kflynn (http://www.alteraforum.com/forum/member.php?u=86819) in this link (http://www.alteraforum.com/forum/showthread.php?t=48398), the below issue can be resolved by padding or extending the most significant bit (bit 23) into bits 24 through 31. I want to know, how could I extend the most significant bit (bit 23) into bits 24 through 31? How could I do that in C code? I am using C code to program Nios II. I was thinking of using bit shifting operation but not knowing in details how by using bit shifting operation, the above could be achieved, any link or resource is much appreciated. Thank you in advance. HI, I have a very simple question but I have no idea what went wrong. Basically I have a 24-bit signed signal from VHDL block fed into Nios II system. I use C code for NIos II system. This is my code:Code:value =IORD_ALTERA_AVALON_PIO_DATA(base);
to read the 24-bit signed signal. I define it asCode: alt_32 value=0;
The problem is it always give me positive value every time read from this line even though I am sure it is negative value from VHDL code.Code: printf("\n value= %d \n", value);
Any idea what went wrong??? sorry for the simple question... Thank you in advance
Link Copied
3 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
the msb is the sign bit, so you could check your 24'th bit using a bitmask, if it is set, change the 32'nd bit and vice versa. Then clear the 24'th bit.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
since you are using Nios, this operation could be easily converted to simple custom instruction, something like:
module ci_pad(
input dataa,
output result
);
assign result = { {8{dataa}}, dataa};
endmodule
alternatively, as PietervanderStar suggested (in C):
value = (value & (0x1 << 24)) ?
value | (0xFF << 24 ) :
value;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I think that C code should actually be:
value = (value & (0x1 << 23)) ?
value | (0xFF << 24 ) :
value;
Notice that you are checking bit 23 to see if it is a 1 or a 0 (not bit 24!).

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page