Jump to content

Recommended Posts

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 by robcarter

Share this post


Link to post
Share on other sites

Hi Rob,

 

An array or structure will keep them together otherwise the linker may put them individually anywhere it can find space.

 

Cheers

 

Reynard

Share this post


Link to post
Share on other sites

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 by trossin

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

Your content will need to be approved by a moderator

Guest
You are commenting as a guest. If you have an account, please sign in.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×