Slc5

mtech2766

Member
Join Date
Jun 2021
Location
Indiana
Posts
20
I am trying to do something the easy way, which I think can be done but I don't know how.
I have a 16 bit register that will give me four groups of four bits depending on the equipment installed.
Bits 0-3 are ignored, 4-7 will give me a value, 8-11 will give me another value, and 12-15 another value.
Each group will be decimal value 2, 3, or 4 in binary.
Can I convert each group of bits to a decimal value while ignoring the rest?
I would then use the HMI to display which equipment was installed.

thanks
 
Brute force method.

For the numeric value in bits 4 - 7:
(Original_Word AND x00F0) / 16

For the numeric value in bits 8 - 11:
(Original_Word AND x0F00) / 256

For the numeric value in bits 12 - 15:
(Original_Word AND xF000) / 4096

The AND function zeroes all bits except for the ones you're interested in.
The divide function shifts the bits toward the least significant by the number of places represented by the power of 2.
 
Last edited:
Steve Bailey's solution is what I would suggest, although you can use MVM instead of AND if you like.

Unfortunately BTD is not supported in a SLC, or I would use that instead of division.
 
Brute force method.

For the numeric value in bits 4 - 7:
(Original_Word AND x00F0) / 16

For the numeric value in bits 8 - 11:
(Original_Word AND x0F00) / 256

For the numeric value in bits 12 - 15:
(Original_Word AND xF000) / 4096

The AND function zeroes all bits except for the ones you're interested in.
The divide function shifts the bits toward the least significant by the number of places represented by the power of 2.
Perhaps those should all be 7s (0x0070; 0x0700; 0x7000), which works because OP said the values will be 2, 3, or 4; if not, then the last one should be:
((Original_Word AND xF000) / 4096) AND 0x0F
A brute-force option is
[XIC Original_Word.4 OTE bits4to7.0]
[XIC Original_Word.5 OTE bits4to7.1]
[XIC Original_Word.6 OTE bits4to7.2]
[OTL bits4to7.3] (optional)

[XIC Original_Word.8 OTE bits8toB.0]
[XIC Original_Word.9 OTE bits8toB.1]
[XIC Original_Word.10 OTE bits8toB.2]
[OTL bits8toB.3] (optional)

[XIC Original_Word.11 OTE bitsCtoF.0]
[XIC Original_Word.12 OTE bitsCtoF.1]
[XIC Original_Word.14 OTE bitsCtoF.2]
[OTL bitsCtoF.3] (optional)
Esoteric (i.e. ugly) version, assuming possible values are only ever 2 or 3 or 4, saves 3 instructions over brute-force:
BST MOV 2 bits4to7
NXB XIC Original_Word.0 OTE bits4to7.0
NXB XIVC Original_Word.2 MOV 4 bits4to7
BND

BST MOV 2 bits8toB
...
But with no BTD, @Steve Bailey's method is probably the cleanest.
 
Last edited:
The FRD and TOD instructions to translate to and from Binary Coded Decimal do exist in the SLC-500 operating system, but you still have to add a bunch of buffer data table elements and divide by 10, 100, 1000 and use the S:13 and S:14 math registers to get the remainders.

I would do this by jumping to a subroutine with nothing but four XIC's and four OTE's for each value. It's brute-force, but it's fast and it's easy for a future user to understand even if the comments are lost.

Dividing by 16, 256, and 4096 also works because the value of a nibble is never more than 4, so the Sign bit in the 16-bit signed integer source word is never true. But it's not a general-purpose solution.
 

Similar Topics

I have wasted a week trying to figure out how to connect an SLC5/03 with my laptop. I do not have and can not Buy the 1747 UIC and PC3 cables. I...
Replies
14
Views
2,544
I am trying to connect to SLC5/03 using an FTDI usb to rs232 with female to female converter at 1 end... however I can not connect to it ... the...
Replies
8
Views
1,263
Good evening. I am in serious need of help. I am trying to connect a Panelview Plus 7 Standard to a SLC5/03(1741-L531) using a Moxa MGate...
Replies
3
Views
625
Hi. I am having trouble establishing comms between an slc5/04 and panel view plus 7 via a PLX51-net-eni. The set up is: 5/04 Channel 0 DF1...
Replies
8
Views
913
Hi All, I have programmed some MSG instruction in SLC5/05 64k CPU series D FW 13 brand new cpu. 2 of the MSG instructions are direct IP to other...
Replies
3
Views
976
Back
Top Bottom