This blog post will walk you through a simple 8086 assembly program designed to perform bitwise operations: AND, OR, XOR and NOT on 8-bit numbers. While these operations have a straightforward purpose, they are foundational when working at low level, manipulating bits, flags and registers. Let’s get started!
data segment
a db 0Ah ; first 8-bit operand (10 decimal)
b db 05h ; second 8-bit operand (5 decimal)
res_and db ? ; result of a AND b
res_or db ? ; result of a OR b
res_xor db ? ; result of a XOR b
res_not db ? ; result of NOT a
data ends
code segment
assume cs:code, ds:data
start:
mov ax, data
mov ds, ax
; load operands into registers
mov al, a
mov bl, b
; AND operation: AL = AL AND BL
and al, bl
mov res_and, al
; reload operands for next operation
mov al, a
mov bl, b
; OR operation: AL = AL OR BL
or al, bl
mov res_or, al
; reload operands for next operation
mov al, a
mov bl, b
; XOR operation: AL = AL XOR BL
xor al, bl
mov res_xor, al
; NOT operation on first operand: AL = NOT AL
mov al, a
not al
mov res_not, al
int 3 ; breakpoint / stop for debug
code ends
end start