OR combines the two operands bit by bit and stores the result in the first. A result bit is 1 when either operand (or both) has a 1 there. Used with a mask, OR switches on the bits where the mask has a 1 and does not touch the others.

dst bitsrc bitresult
000
011
101
111
0100 0001 AL = 41h ("A")
OR 0010 0000 mask 20h
= 0110 0001 AL = 61h ("a")

Forms and flags

The operand rules are the same as for AND: register or memory destination, register, memory or immediate source, equal sizes, no memory-to-memory, no segment registers. CF and OF are cleared, SF ZF PF follow the result, AF is undefined.

Idioms

Set a bit in a hardware register or a flag byte: OR AL, 3 turns on bits 0 and 1 (the guide's speaker example does this with port 61h). Make a digit printable: values 0..9 OR 30h give "0".."9". Lowercase an ASCII letter: OR AL, 20h. Glue two parts together once they sit in different bits, for example a high nibble already shifted into place OR a low nibble.

An old habit is OR AX, AX to check a register: the value does not change, but ZF and SF now say whether it is zero or negative. TEST AX, AX does the same and states the intent more clearly.

Prints 01000001 01100001 a7
MOV AL, 41h ; 0100 0001 = "A"
CALL SHOWBIN
OR AL, 20h ; set bit 5
CALL SHOWBIN ; 0110 0001
MOV DL, AL
MOV AH, 02h
INT 21h ; prints "a"
MOV AL, 7
OR AL, 30h ; 7 -> "7"
MOV DL, AL
MOV AH, 02h
INT 21h
SHOWBIN PROC NEAR ; print AL as 8 binary digits and a space
PUSHF ; keep the caller's flags
PUSH AX
PUSH BX
PUSH CX
PUSH DX
MOV BL, AL
MOV CX, 8
NEXTBIT:
SHL BL, 1 ; the top bit falls into CF
MOV DL, "0"
ADC DL, 0 ; "0" + CF = "0" or "1"
MOV AH, 02h
INT 21h
LOOP NEXTBIT
MOV DL, " "
MOV AH, 02h
INT 21h
POP DX
POP CX
POP BX
POP AX
POPF
RET
SHOWBIN ENDP