Slide 11.5: AND instructions
Slide 11.7: XOR instruction
Home

OR Instruction


The OR instruction performs a boolean OR operation between each pair of matching bits in two operands and places the result in the destination.

OR — Inclusive Logical OR

Usage: OR dest, src

Flag O D I S Z A P C
Result 0     * * ? * 0

Logical inclusive OR of the two operands returning the result in the destination. Any bit set in either operand will be set in the destination.
Clocks
Operands 286 386 486 Size Bytes
reg, reg 2 2 1 2
mem, reg 7 7 3 2-4
reg, mem 7 6 2 2-4
reg, immed 3 2 1 3-4
mem8, immed8 7 7 3 3-6
mem16, immed16 7 7 3 3-6
accum, immed 3 2 1 2-3

The operands can be 8, 16, or 32 bits, and they must be the same size. The OR instruction is often used to set selected bits and preserve others. We can also use OR a number with itself (or zero) to obtain certain information about its value. Therefore, you can use OR instruction instead of CMP instruction for finding whether or not the operand is zero or negative.

 Zero Input Test   Negative Input Test 
 INCLUDE Irvine32.inc
 .data
 prompt1 BYTE "Zero.", 0
 prompt2 BYTE "Not zero.", 0
 .code
 main PROC
       call  ReadInt
       or    eax, eax
       

mov edx, OFFSET prompt2 call WriteString exit ZERO: mov edx, OFFSET prompt1 call WriteString exit main ENDP END main
 INCLUDE Irvine32.inc
 .data
 prompt1 BYTE "Negative.", 0
 prompt2 BYTE "Not negative.", 0
 .code
 main PROC
       call  ReadInt
       or    eax, eax
       

mov edx, OFFSET prompt2 call WriteString exit NEGA: mov edx, OFFSET prompt1 call WriteString exit main ENDP END main