robcarter 0 Report post Posted December 3, 2014 (edited) Hi In an application i have to implement a 40 bit shift register, does anyone know if i define 5 char variables will they always be placed in consecutive memory locations? e.g using volatile unsigned char data1,data2,data3,data4,data5; or using volatile unsigned long date1; volatile unsigned char data2; I am using volatile because they are accessed from an interrupt. or would an array be better? thanks Edited December 3, 2014 by robcarter Quote Share this post Link to post Share on other sites
Reynard 0 Report post Posted December 3, 2014 Hi Rob, An array or structure will keep them together otherwise the linker may put them individually anywhere it can find space. Cheers Reynard Quote Share this post Link to post Share on other sites
robcarter 0 Report post Posted December 4, 2014 Thanks, if I use a structure can i access it from assembly for example using: movf _structure_name.element_name,w Quote Share this post Link to post Share on other sites
trossin 0 Report post Posted December 5, 2014 (edited) Why do the variables have to be together? The following code pieces can shift a 40 bit variable left or right by one bit and shift in the input Input. The 40 bit variable in Verilog speak is {High[31:0],Low[7:0]}. unsigned long High; unsigned char Low,Carry; unsigned char Input; // Shift Left Carry = (Low & 0x80) ? 1 : 0; High = (High<<1) | Carry; Low = (Low<<1) | Input; // Shift Right Carry = (High & 1) ? 0x80 : 0; High = (High>>1) | (Input ? 0x80000000 : 0); Low = (Low>>1) | Carry; Edited December 5, 2014 by trossin Quote Share this post Link to post Share on other sites
robcarter 0 Report post Posted December 8, 2014 i theory they don't need to be together, but I wanted to implement the shifting in assembler because the 36 shifts (I don't need all 40 bits) are output serially on an interupt and didn't want the extra overhead of bank switching code being inserted. I think the best way is probably to assign fixed addresses at 0x7? so they an be accessed from any bank. Quote Share this post Link to post Share on other sites