Tag Archives: 8086

Understanding INT 3h vs INT 21h in 8086 Assembly

In 8086 assembly programming, interrupts play a crucial role in handling various operations, from debugging to system calls. Two commonly used interrupts are <strong>INT 3h</strong> (Breakpoint Interrupt) and <strong>INT 21h</strong> (DOS Interrupt). While both involve interrupt handling, their functionalities and use cases are completely different.

In this blog post, we will explore the differences between INT 3h and INT 21h, their respective use cases, and practical examples to understand their behavior.

TL;DR

  • <strong>INT 3h</strong> is used for debugging; it stops execution and hands control to the debugger.
  • <strong>INT 21h</strong> is used for system services like displaying messages, reading input, and terminating the program.
  • Key Difference: INT 3h is a 1-byte instruction (CC), while INT 21h requires function numbers in AH to specify system calls.
Continue reading Understanding INT 3h vs INT 21h in 8086 Assembly

8086 Assembly Program to Add Two 16-bit Numbers with Carry Handling

In this blog post, we’ll explore an 8086 assembly language program that adds two 16-bit numbers while also checking for a carry flag.

; Data Segment

data segment
    a dw 0FFFFh      ; Example value that will cause a carry
    b dw 0001h       ; Example value
    c dw ?           ; To store result
    carry_flag db 0  ; To store carry (0 or 1)
data ends

; Code Segment

code segment
assume cs:code, ds:data
start:
    mov ax, data
    mov ds, ax      ; Initialize data segment

    mov ax, a       ; Load first number
    mov bx, b       ; Load second number
    add ax, bx      ; Perform addition

    mov c, ax       ; Store result in 'c'

    jc carry_occurred  ; Jump if carry flag is set
    mov carry_flag, 0  ; No carry, store 0
    jmp end_program    

carry_occurred:
    mov carry_flag, 1  ; Store carry flag as 1

end_program:
    int 3             ; Halt program

code ends
end start
Continue reading 8086 Assembly Program to Add Two 16-bit Numbers with Carry Handling

8086 Data Directives: DB, DW, DD, DQ, DT, DUP, EQU, PTR, and OFFSET

Data directives are assembler instructions, not CPU instructions — they tell the assembler how much memory to reserve and what value to store there at load time. The CPU never executes a DB or DW; it simply finds the bytes already in memory when it accesses that address at runtime. Choosing the right directive matters: use DB for bytes and strings, DW for 16-bit integers and addresses, DD for far pointers and 32-bit values, and DUP to initialise arrays without typing each value individually.

Continue reading 8086 Data Directives: DB, DW, DD, DQ, DT, DUP, EQU, PTR, and OFFSET

Mix (C++ and Assembly) Program to Find Largest Number from Given Numbers

This C++ program demonstrates how to find the largest element from a set of five integers using 8086 assembly instructions embedded directly into the code. The inline assembly helps perform comparisons and updates the result with the highest value found.

Continue reading Mix (C++ and Assembly) Program to Find Largest Number from Given Numbers

Mix (C++ and Assembly) Program to Sort Numbers in Ascending Order

This post demonstrates how to sort an array of integers using inline assembly in C++. Here, we perform sorting in ascending order by comparing and swapping adjacent elements using embedded assembly within a C++ program.

#include<iostream.h>
#include<conio.h>
void main()
{
    int a[5], x, y;
    int i, j;
    cout << "\n Enter 5 Numbers:";
    for(i = 0; i < 5; i++)
    {
        cin >> a[i];
    }
    //Sorting
    for(i = 0; i < 4; i++)
    {
        for(j = 0; j < 4; j++)
        {
            x = a[j];
            y = a[j + 1];
            _asm {
                mov ax, x
                mov bx, y
                cmp ax, bx
                jl nxt
                mov cx, ax
                mov ax, bx
                mov bx, cx
                mov x, ax
                mov y, bx
            }
            nxt:
            a[j] = x;
            a[j + 1] = y;
        }
    }
    cout << "\n Sorted Array:";
    for(i = 0; i < 5; i++)
        cout << a[i] << " ";
    getch();
}
Continue reading Mix (C++ and Assembly) Program to Sort Numbers in Ascending Order

Mix (C++ and Assembly) Program to Find Smallest Number from Given Numbers

This C++ program demonstrates how to find the smallest number from an array using inline 8086 assembly language instructions. The logic involves comparing each array element and storing the smallest found so far using cmp and conditional jump instructions.

#include<iostream.h>
#include<conio.h>

void main()
{
    short a[5], x, y, res;
    short i, j;
    y = 999; // Initialize with a large number

    cout << "\n Enter 5 Numbers:";
    for (i = 0; i < 5; i++) {
        cin >> a[i];
    }

    asm {
        mov bx, y
    }

    // Finding smallest
    for (i = 0; i < 5; i++) {
        x = a[i];
        asm {
            mov ax, x
            mov bx, y
            cmp ax, bx
            jnb nxt   // Jump if not below (i.e., current is not smaller)
            mov bx, ax
            mov y, bx
        }
    nxt:
    }

    asm {
        mov res, bx;
    }

    cout << "\n Smallest Element:" << res;
    getch();
}
Continue reading Mix (C++ and Assembly) Program to Find Smallest Number from Given Numbers