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 bit | src bit | result |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 1 |
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.
MOV AL, 41h ; 0100 0001 = "A"CALL SHOWBINOR AL, 20h ; set bit 5CALL SHOWBIN ; 0110 0001MOV DL, ALMOV AH, 02hINT 21h ; prints "a"MOV AL, 7OR AL, 30h ; 7 -> "7"MOV DL, ALMOV AH, 02hINT 21hSHOWBIN PROC NEAR ; print AL as 8 binary digits and a spacePUSHF ; keep the caller's flagsPUSH AXPUSH BXPUSH CXPUSH DXMOV BL, ALMOV CX, 8NEXTBIT:SHL BL, 1 ; the top bit falls into CFMOV DL, "0"ADC DL, 0 ; "0" + CF = "0" or "1"MOV AH, 02hINT 21hLOOP NEXTBITMOV DL, " "MOV AH, 02hINT 21hPOP DXPOP CXPOP BXPOP AXPOPFRETSHOWBIN ENDP