Page 1 of 1

Bits manipulation

Posted: 23 Mar 2017 13:06
by Alessandro Fulignani
Hi All,

Is there a way to set multiple bit in a single instruction line?

Example:

dim TEMP as Byte

dim X as sbit at temp.b0
dim Y as sbit at temp.b1
dim Z as sbit at temp.b2
dim A as sbit at temp.b3

now, if i want to set four bits, i have to do that:

X = 1
Y = 1
Z = 1
A = 1

Then the assember output will address the RAM four times wasting a lot of time and space.

I wonder if there is a possibility to do something like that:

X+Y+Z+A = 1

or

X.Y.Z.A = 1

that would even mean that the assembler will put a single calculated value during the compiling phase.


Thank You

Alessandro

Re: Bits manipulation

Posted: 23 Mar 2017 17:42
by s_sergiu
Hi,

You can do it like that:

Temp = Temp and %1111

Sergiu

Re: Bits manipulation

Posted: 23 Mar 2017 17:55
by Alessandro Fulignani
Thank you Sergiu

I know that.

My problem is about readibility of the code. That why i putted alias to the bits...

I would like to read the names of the bits

Thank you,

Alex

Re: Bits manipulation

Posted: 24 Mar 2017 12:53
by teprojects2
Alessandro Fulignani wrote:Hi All,

Is there a way to set multiple bit in a single instruction line?

Example:

dim TEMP as Byte

dim X as sbit at temp.b0
dim Y as sbit at temp.b1
dim Z as sbit at temp.b2
dim A as sbit at temp.b3

now, if i want to set four bits, i have to do that:

X = 1
Y = 1
Z = 1
A = 1

Then the assember output will address the RAM four times wasting a lot of time and space.

Otherwise I need to use Arduino Mega 2560. So, I wonder if there is a possibility to do something like that:

X+Y+Z+A = 1

or

X.Y.Z.A = 1

that would even mean that the assembler will put a single calculated value during the compiling phase.


Thank You

Alessandro
did you try this?

X=Y=Z=A=1;

Re: Bits manipulation

Posted: 30 Aug 2021 11:08
by Alessandro Fulignani
Good Morning,

Thank you for your suggestion. Yes i did. Does not work.

Alex