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 NumbersCategory Archives: Mix (C++ and Assembly)
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();
}
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();
}
Mix (C++ and Assembly) Program to Count Number of 0’s and 1’s
This post demonstrates how to count the number of 0
s and 1
s in the binary representation of an integer using inline assembly in a C++ program. This is an excellent example of bit-level operations using low-level assembly instructions.
Mix (C++ and Assembly) Program to Convert Binary Number into BCD Format
This post explores how to convert a 4-digit binary number (entered as a decimal) into its equivalent Binary Coded Decimal (BCD) form using inline assembly in a C++ program.
Continue reading Mix (C++ and Assembly) Program to Convert Binary Number into BCD FormatMix (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 FormatMix (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();
}