Tag Archives: Assembly

8086 Assembly Program to Convert Binary Number into BCD Format

In this blog post, we will explore an 8086 assembly language program designed to convert a binary number into its Binary-Coded Decimal (BCD) format. This conversion is essential in applications where binary numbers need to be represented in a decimal-like format, such as digital displays or interfaces that require human-readable numbers.

The following assembly program performs the conversion:

DATA SEGMENT
NO1 DB "1001000000110110"
D1 DW 4 DUP (?)
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE, DS:DATA
START:
MOV AX, DATA
MOV DS, AX
LEA SI, NO1
LEA DI, D1
MOV CX, 04H
TOP:
MOV BX, 00H
MOV AX, [SI]
ROR AX, 1
JNC P2
ADD BX, 08H
P2:
INC SI
MOV AX, [SI]
ROR AX, 1
JNC P3
ADD BX, 04H
P3:
INC SI
MOV AX, [SI]
ROR AX, 1
JNC P4
ADD BX, 02H
P4:
INC SI
MOV AX, [SI]
ROR AX, 1
JNC P5
ADD BX, 01H
P5:
MOV [DI], BX
INC DI
INC SI
DEC CX
JNZ TOP
INT 3
CODE ENDS
END START
Continue reading 8086 Assembly Program to Convert Binary Number into BCD Format

8086 Assembly Program to Convert BCD Number into Binary Format

​In this blog post, we’ll explore how to convert a BCD (Binary-Coded Decimal) number into its binary equivalent using an 8086 assembly language program. The following code snippet demonstrates this process:

DATA SEGMENT
NO1 DB "9036"
D2 DB ?
D1 DB 16 DUP(?)
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE, DS:DATA
START:
MOV AX, DATA
MOV DS, AX
LEA SI, NO1
LEA DI, D1
MOV CX, 04H
TOP:
MOV AL, [SI]
MOV DX, 0CH
UP1:
ROL AX,1
DEC DX
JNZ UP1
AND AX, 1111000000000000B
MOV DX, 04H
UP2:
ROL AX, 1
JNC DN
MOV BX, 1
MOV [DI], BX
JMP DN2
DN:
MOV BX, 0
MOV [DI], BX
DN2:
INC DI
DEC DX
JNZ UP2
INC SI
DEC CX
JNZ TOP
INT 3
CODE ENDS
END START
Continue reading 8086 Assembly Program to Convert BCD Number into Binary Format

Mix (C++ and Assembly) Program to Convert BCD Number into Binary Format

This post demonstrates how to convert a Binary Coded Decimal (BCD) number into its binary equivalent using inline assembly within a C++ program. The conversion is done by isolating and processing each BCD digit and calculating its decimal equivalent.

Continue reading Mix (C++ and Assembly) Program to Convert BCD Number into Binary Format

Mix (C++ and Assembly) Program to Find Reverse of an Array

This post explores how to reverse an array of integers using inline assembly within a C++ program. The program swaps elements from the start and end of the array using low-level assembly instructions.

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

void main()
{
    int nos[5], x, y;
    cout << "\n Enter 5 numbers:";
    int i, j;
    for(i = 0; i < 5; i++)
    {
        cin >> nos[i];
    }
    for(i = 0, j = 4; i < 3; i++, j--)
    {
        x = nos[i];
        y = nos[j];
        _asm{
            mov ax, x
            mov bx, y
            mov cx, ax
            mov ax, bx
            mov bx, cx
            mov x, ax
            mov y, bx
        }
        nos[i] = x;
        nos[j] = y;
    }
    cout << "\n Reverse:";
    for(i = 0; i < 5; i++)
    {
        cout << nos[i] << " ";
    }
    getch();
}
Continue reading Mix (C++ and Assembly) Program to Find Reverse of an Array