Jump to content
Sign in to follow this  
KevKelley

Using Bits From a Variable

Recommended Posts

I was looking at possibly freeing up variables if necessary and was curious if you could use part of a variable for a counter and the rest for bit operations?

 

So based of my understanding, say I have a counter and it only ever used up to 4 bits (%00000000 - %00001010).

 

Can I use the 4 bits that are never used or when a variable is used does it check all of the bits?

 

So if I were to check for x{7} while having the counter at 10 (%10001010), would it read both or by turning on x{7} would it be read as 138?

Share this post


Link to post
Share on other sites

There's only one bit 7, but the counter would be 138, you can turn the first half into a four bit variable aka nibble, it can only count to 15.

 

 

   macro _Set_Lo_Nibble

   {1}=(({2}^{1})&$0F)^{1}

end

 

   def PEEK_Counter = x&$0F

   def POKE_Counter = callmacro _Set_Lo_Nibble x

 

 

To set it to 0

POKE_Counter 0 ;notice no equal sign

 

To check if it's 15

if PEEK_Counter = 15 then...

 

To add 1

temp5 = (PEEK_Counter) + 1 

POKE_Counter  temp5

 

Then you can use bits 4-7 for other things, it won't affect peeking at the counter since it only checks the first four bits

 

 

  • Like 1

Share this post


Link to post
Share on other sites

Ah. Okay. Thanks! I remember reading about nybble variables early on but never knew what for but now it makes sense. I will definitely play around with this. 

 

So then if I have it count up and need to change back to 0 then I would do:

 

If PEEK_Counter = 15 then POKE_Counter 0

 

And then add to it using a temp variable.

 

I'm sure I'll get the hang of this. Thanks very much!

 

  • Like 1

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
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...
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...