Sign in to follow this  
Followers 0
308guru

Is there a simple way of resetting ranges of B locations ?

7 posts in this topic

I would like to reset various ranges of B bits to zero and I'm wondering if there's an efficient way of doing so. Let's say one range I need to reset is B3:8/0 to B3:8/6. Do I have to do 7 individual move commands to move a zero into those locations? I tried using MOV 0 into #B3:8/0 with a length of 7 but I got an error. I have done that with other N and F files and it works great. Any suggestions? I have quite a few ranges to reset and I just want to keep programming simple and neat. Thanks. Edited by mckeand13

Share this post


Link to post
Share on other sites
If you are using a SLC or MicroLogix processor; You could use a MVM [Masked Move].

Share this post


Link to post
Share on other sites
Oops, helpful info. I'm using a ML1100. I haven't used that command. I'll take a look at the instructions.

Share this post


Link to post
Share on other sites
You are working with individual bits and ranges of bits. The MOV is a word (16 bit) command Move with Mask MVM will allow you to pick which bits within a word to zero.

Share this post


Link to post
Share on other sites
The bitwise AND instruction, not the MVM instruction, is the appropriate instruction for performing this operation. AND B3:8 FF80H B3:8 //clears bits B3:8/0 through B3:8/6. MVM requires an address for both source and destination, and you cannot use the same address for both source and destination because the end result would be no net change in the word contents. You would have to have a zero word reserved somewhere else. A bitwise AND is a cleaner solution. Edited by Alaric

Share this post


Link to post
Share on other sites
If you are careful about how you organize your memory, you can still use the MOV operation to set/clear a bunch of bits at one time. Just organize your bits in groups of 16. Then: CLR B3:0 ...does the trick. Also, the CLR instruction is cleaner, clearer, and faster than using MOV 0 xx to clear a location. ...and both are far better than CPT xx 0. This is called strength reduction....always using the operation that requires the least power or "strength" to accomplish your goal.

Share this post


Link to post
Share on other sites
Thanks everyone for all of the good suggestions.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0