TConnolly
Lifetime Supporting Member
juice76 said:First, use a move instruction to copy the alarm word into another word. Let's call this word "ExamWord". Use a "Bit Shift" instruction to sequentially examine all the bits in the "ExamWord". When a bit has a value of 1, use a counter to count it. At the end of each word examination cycle (after you've looked at all the bits), reset the counter to 0 and move the alarm word into "ExamWord" again. If you count 3 bits or more in any examination cycle, set your shutdown bit.
To expand on this method, what if there were a way to only count the set bits and automatically skip over the clear bits? This way if there are only two set bits, we only loop twice. If there are four bits, we only loop four times.
While (ExamWord > 0) {
Examword := Examword & (ExamWord-1)
Count := Count + 1
}
In AB LL:
----------------------+----------+-
|MOV |
| N |
| ExamWord |
+----------+
----------------------+----------+-
|MOV |
| 0 |
| Count |
+----------+
-[LBL 1]-+----------+----+--+------------+-
|GRT | | |SUB |
| ExamWord | | | ExamWord |
| 0 | | | 1 |
+----------+ | | A |
| +------------+
|
+--+------------+--
| |AND |
| | ExamWord |
| | A |
| | ExamWord |
| +------------|
|
+--+------------+--
| |ADD |
| | Count |
| | 1 |
| | Count |
| +------------|
|
+--------<JMP 1>----
Logic can also be added for this app so that you stop looping when count=3.