Sign in to follow this  
Followers 0
RhodyCho

Integer Shift

7 posts in this topic

Hi, using RSLogix500 on some ML1400's. I'm interested in looking at the second half of a 16 bit word. Actually I want to shift bits 8-15 of say N7:0 to another integer word, say N7:1 bits 0-7. I have to do this for a number of words so doing it bitwise is a bit of a hassle. Any suggestions would be appreciated.
1 person likes this

Share this post


Link to post
Share on other sites
Normally an AND of FF00h followed by a divide by 256 would be enough to shift the bits except for that problematic bit 15. If it's on the number is considered negative and errors start arising. If available MOV the N register to an L register then do the AND and DIV sending the result to your desired target. RSLogix500 accepted those instructions for a 1400. But I can't test it on an actual unit. BST MOV N7:0 L9:0 NXB AND L9:0 -256 L9:0 NXB DIV L9:0 256 N7:1 BND (the -256 is the 16 bit interpretation of the hex value FF00h) Edited by b_carlton
1 person likes this

Share this post


Link to post
Share on other sites
I think this will work, I don't have my emulator set up. But it works on a binary calculator! The trick is using the mask to filter out the bits you don't want to look at, it shows up in hexadecimal form.: for instance: 1010101010101010 Source N7:0 1111111100000000 Mask 1010101000000000 Result N7:1 Next divide the result by 255 to truncate the first byte of data and the result to N7:2 Hope that Helps

Share this post


Link to post
Share on other sites
I think to move bits 8-15 to bits 0-7 you could also use the swp instruction.
1 person likes this

Share this post


Link to post
Share on other sites
I like Chelton's answer much better than mine. I haven't used that instruction before. Nice and short. Edited by b_carlton

Share this post


Link to post
Share on other sites
Thanks for the responses, good stuff. I'm a bit upset at myself for not thinking of that divide method. Think I'll have a few beers for atonement.

Share this post


Link to post
Share on other sites
I'm voting for that SWP Instruction. If this were an RSLogix5 or RSlogix5000 PLC I'd suggest the BTD - "Bit Field Distributor" but alas RA didn't port that fine instruction to the 500 family.

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