Tag Archives: Assembly

8086 Assembly Program to Multiply Two 16-bit Numbers

Multiplication in 8086 assembly has one important difference from addition and subtraction: you do not choose the destination. The MUL instruction always multiplies the implicit register AX by the operand you supply, and always puts the 32-bit result into DX:AX. Understanding that implicit contract — and always saving both halves of the result — is the key to correct multiplication programs. This post walks through a working implementation in three environments: MASM/TASM, emu8086, and NASM.

Continue reading 8086 Assembly Program to Multiply Two 16-bit Numbers

8086 Assembly Program to Subtract Two 16-bit Numbers

Assembly language offers a hands-on approach to understanding how computers perform basic arithmetic at a low level. Subtraction in 8086 assembly follows the same register-first pattern as addition — but with one extra detail worth getting right: operand order. SUB AX, BX computes AX − BX, not BX − AX. Getting that backwards produces a wrong result with no assembler warning. This post walks through a working implementation in three environments: MASM/TASM, emu8086, and NASM.

Continue reading 8086 Assembly Program to Subtract Two 16-bit Numbers

8086 Assembly Program to Divide Two 16-bit Numbers

Division in 8086 assembly is the most instruction-constrained of the four arithmetic operations. Unlike addition or subtraction, the DIV instruction does not let you choose which registers hold the dividend and quotient — the hardware fixes those roles permanently. Understanding why the registers are wired this way is the key to writing correct division programs and avoiding the dreaded divide overflow exception. This post walks through a working implementation in three assembler environments: MASM/TASM, emu8086, and NASM.

Continue reading 8086 Assembly Program to Divide Two 16-bit Numbers

8086 Assembly Program for Addition of Two 8-bit Numbers

Adding two 8-bit numbers is the entry point into 8086 assembly arithmetic — simpler than 16-bit addition in operand size, but identical in structure. You will see the same segment setup, the same register-first constraint, and the same result-storage pattern. This post covers a working implementation in three environments: MASM/TASM (classic DOS toolchain), emu8086 (the Windows emulator used in most college labs), and NASM (modern open-source assembler). All versions are tested and produce verifiable output.

Continue reading 8086 Assembly Program for Addition of Two 8-bit Numbers

8086 Assembly Program to Add Two 16-bit Numbers

Adding two 16-bit numbers is one of the first real programs every assembly language student writes — and for good reason. It touches every foundational concept at once: segment registers, data declarations, arithmetic instructions, result storage, and program termination. This post walks through a working implementation in three assembler environments: MASM/TASM (the classic DOS toolchain), emu8086 (the popular Windows emulator used in college labs), and NASM (the modern open-source assembler). All examples are tested and produce verifiable output.

Continue reading 8086 Assembly Program to Add Two 16-bit Numbers

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

This post demonstrates how to sort an array of integers using inline assembly in C++. We use basic comparison and swap logic in assembly embedded 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
                jge 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 Descending Order