Tag Archives: Assembly

8086 Assembly Program to Divide Two 16 bit Numbers

When working with assembly language, one of the fundamental operations is division. In this blog post, we will explore an 8086 assembly program that divides two 16-bit numbers using the DIV instruction.

The following program takes two 16-bit numbers stored in memory, performs division, and stores the result.

data segment
a dw 4444h
b dw 0002h
c dw ?
data ends

code segment
assume ds:data, cs:code
start:
mov ax,data
mov ds,ax
mov ax,a
mov bx,b
div bx
mov c,ax
int 3
code ends
end start
Continue reading 8086 Assembly Program to Divide 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