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 NumbersTag Archives: 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();
}
8086 Assembly Program to Find Smallest Number from Given Numbers
In this blog post, we’ll explore how to find the smallest number from a given set of values using an 8086 assembly language program. The following code snippet demonstrates this process:
data segment STRING1 DB 08h,14h,05h,0Fh,09h res db ? data ends code segment assume cs:code, ds:data start: mov ax, data mov ds, ax mov cx, 04h mov bl, 79h LEA SI, STRING1 up: mov al, [SI] cmp al, bl jge nxt mov bl, al nxt: inc si dec cx jnz up mov res,bl int 3 code ends end startContinue reading 8086 Assembly Program to Find Smallest Number from Given Numbers
8086 Assembly Program to Sort Numbers in Descending Order
In this blog post, we will explore an 8086 assembly language program designed to sort a list of numbers in descending order. Sorting is a fundamental operation in computer science, and understanding how to implement it at the assembly level provides valuable insights into low-level programming and processor operations.
The following assembly program sorts an array of numbers in descending order using the bubble sort algorithm:
DATA SEGMENT STRING1 DB 99H,12H,56H,45H,36H DATA ENDS CODE SEGMENT ASSUME CS:CODE,DS:DATA START: MOV AX,DATA MOV DS,AX MOV CH,04H UP2: MOV CL,04H LEA SI,STRING1 UP1:MOV AL,[SI] MOV BL,[SI+1] CMP AL,BL JNC DOWN MOV DL,[SI+1] XCHG [SI],DL MOV [SI+1],DL DOWN: INC SI DEC CL JNZ UP1 DEC CH JNZ UP2 INT 3 CODE ENDS END STARTContinue reading 8086 Assembly Program to Sort Numbers in Descending Order
8086 Assembly Program to Sort Numbers in Ascending Order
In this blog post, we will explore an 8086 assembly language program designed to sort a list of numbers in ascending order. Sorting is a fundamental operation in computer science, and understanding how to implement it at the assembly level provides valuable insights into low-level programming and processor operations.
The following assembly program sorts an array of numbers in ascending order using the bubble sort algorithm:
DATA SEGMENT STRING1 DB 99H,12H,56H,45H,36H DATA ENDS CODE SEGMENT ASSUME CS:CODE,DS:DATA START: MOV AX,DATA MOV DS,AX MOV CH,04H UP2: MOV CL,04H LEA SI,STRING1 UP1: MOV AL,[SI] MOV BL,[SI+1] CMP AL,BL JC DOWN MOV DL,[SI+1] XCHG [SI],DL MOV [SI+1],DL DOWN: INC SI DEC CL JNZ UP1 DEC CH JNZ UP2 INT 3 CODE ENDS END STARTContinue reading 8086 Assembly Program to Sort Numbers in Ascending Order
8086 Assembly Program to Count Number of 0’s and 1’s from a String
In this blog post, we’ll explore how to count the number of ‘0’s and ‘1’s in a binary string using an 8086 assembly language program. The following code snippet demonstrates this process:
DATA SEGMENT STR1 DB "00011100" NZ DW ? NO DW ? DATA ENDS CODE SEGMENT ASSUME CS:CODE, DS:DATA START: MOV AX, DATA MOV DS, AX LEA SI, STR1 MOV BX, 00H MOV DX, 00H MOV CX, 08H UP: MOV AX, [SI] ROR AX, 1 JNC ZE INC BX JMP DN ZE: INC DX DN: INC SI DEC CX JNZ UP MOV NZ, DX MOV NO, BX INT 3 CODE ENDS END STARTContinue reading 8086 Assembly Program to Count Number of 0’s and 1’s from a String