How to shift register?

For C and ASSEMBLY users to post questions and code snippets for programming in C and ASSEMBLY. And for any other C or ASM course related questions.

Moderators: Benj, Mods

Post Reply
User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: How to shift register?

Post by Benj »

Hello

If your shifting a variable then you can do so inside a calculation icon as follows.

var = var >> 1

will shift one place to the right

var = var << 1

will shift one place to the left

var = var >> 1 is the same as var = var / 2
var = var >> 2 is the same as var = var / 4

A right shift can also be done as a divide.

var = var << 1 is the same as var = var * 2
var = var << 2 is the same as var = var * 4

A left shift can also be done as a multiply.

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: How to shift register?

Post by Benj »

Hello

Instead of using this,

FCV_PORTB = FCV_PORTB << 1;
FCV_PORTB = FCV_PORTB << 2;
FCV_PORTB = FCV_PORTB << 3;

Try just using the one shift. The result is stored back in the register.

FCV_PORTB = FCV_PORTB << 1;

Post Reply