Category Archives: 8086 MASM

8086 Assembly Program for Bitwise Operations: AND, OR, XOR, and NOT

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
Continue reading 8086 Assembly Program for Bitwise Operations: AND, OR, XOR, and NOT

8086 MASM Assembly Program for Addition of Two 8-bit Numbers

This blog post will guide you through a MASM (Microsoft Macro Assembler) program that performs the addition of two 8-bit numbers. While this is a fundamental operation, it demonstrates crucial assembly programming concepts such as data handling, register usage, and memory storage. Let’s dive in!

Assembly Code

    .model small
    .data
    a db 09h
    b db 02h
    c dw ?
    
    .code
    main proc
        mov ax, @data
        mov ds, ax
        
        mov al, a
        mov bl, b
        add al, bl
        
        mov ah, 0
        mov c, ax
        
        int 3  ; Breakpoint interrupt
        
        mov ax, 4C00h  ; Exit program
        int 21h
    main endp
    
    end main
Continue reading 8086 MASM Assembly Program for Addition of Two 8-bit Numbers