Bitwise (output instruction)

OR: Bitwise OR

Writes the bitwise OR of two registers.

Also called: word OR, merge bits.

OR(number, a, b)

Arguments

NameWhat it isAcceptsDefault
destinationWhat the instruction acts ona registerrequired
aValue Aa number or a tag0
bValue Ba number or a tag0

Arguments are positional and this table is generated from the simulator's own instruction registry, so it always matches what the engine accepts.

What it does

OR walks two registers bit by bit and writes a 1 wherever either input had a 1. Like AND, it is word logic and not the parallel branch that puts two contacts in an either-or on a rung.

It merges. Two alarm words from two parts of a machine become one summary word, and a single test against that summary answers whether anything at all is wrong. Set a bit without disturbing the others by ORing in a value with just that bit in it.

Because anything ORed with 1 is 1, OR can only ever add bits to a value. It never clears one. Clearing is AND's job, with the mask inverted.

A rung you can run

One summary word for two alarm areas

RUNG 1OR Alarm_SummaryAlarm_Wo… or Alarm_Wo…RUNG 2Alarm_Summary≠ 0Any_Alarm_ActiveRUNG 3AND Critical_AlarmsAlarm_Su… and 7RUNG 4Critical_Alarms≠ 0Critical_Alarm
OR(Alarm_Summary,Alarm_Word_1,Alarm_Word_2)
NEQ(Alarm_Summary,0)OTE(Any_Alarm_Active)
AND(Critical_Alarms,Alarm_Summary,7)
NEQ(Critical_Alarms,0)OTE(Critical_Alarm)

Set a bit in either alarm word and the summary picks it up, so one compare answers whether anything is wrong anywhere. The AND underneath then narrows the same summary to the three bits that are worth stopping the machine for. Try Alarm_Word_1 at 4 and then at 16 to see the difference.

Run this rung in the simulator

What it is called on other controllers

PlatformEquivalent
Rockwell (Studio 5000)OR
Siemens (TIA Portal)OR
Mitsubishi (GX Works)WOR
CODESYS and IEC 61131-3OR

Common mistakes

  • Expecting it to clear a bit. OR can only set. To turn a bit off, AND with a mask that has a 0 in that position and 1s everywhere else.
  • Confusing it with a parallel branch. Two contacts in parallel are an either-or on one rung. OR combines two registers.

Practise it

Interactive exercises that use OR. Each one checks your ladder against a real scan.

Related instructions

All ladder logic instructions