Bits manipulation

General discussion on mikroBasic PRO for ARM.
Post Reply
Author
Message
Alessandro Fulignani
Posts: 101
Joined: 04 Nov 2016 13:09

Bits manipulation

#1 Post by Alessandro Fulignani » 23 Mar 2017 13:06

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

s_sergiu
Posts: 77
Joined: 10 Jan 2012 15:09

Re: Bits manipulation

#2 Post by s_sergiu » 23 Mar 2017 17:42

Hi,

You can do it like that:

Temp = Temp and %1111

Sergiu

Alessandro Fulignani
Posts: 101
Joined: 04 Nov 2016 13:09

Re: Bits manipulation

#3 Post by Alessandro Fulignani » 23 Mar 2017 17:55

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

teprojects2
Posts: 27
Joined: 21 Jan 2017 10:44
Location: Lahore
Contact:

Re: Bits manipulation

#4 Post by teprojects2 » 24 Mar 2017 12:53

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;

Alessandro Fulignani
Posts: 101
Joined: 04 Nov 2016 13:09

Re: Bits manipulation

#5 Post by Alessandro Fulignani » 30 Aug 2021 11:08

Good Morning,

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

Alex

Post Reply

Return to “mikroBasic PRO for ARM General”