This program demonstrates how to compare two integers using 8086 inline assembly in C++. By leveraging assembly instructions like sub
and conditional jump js
, the program determines which number is greater.
#include<iostream.h>
#include<conio.h>
void main() {
clrscr();
short a;
short b;
cout << "\n Enter First Number:";
cin >> a;
cout << "\n Enter Second Number:";
cin >> b;
asm mov ax, 0000h // Clear AX
asm mov bx, 0000h // Clear BX
asm mov ax, a // Load first number into AX
asm mov bx, b // Load second number into BX
asm sub ax, bx // Subtract BX from AX
asm js true // Jump if result is negative (AX < BX)
cout << "\n " << a << " is greater than " << b;
asm jmp end // Skip 'true' block
true:
cout << "\n " << b << " is greater than " << a;
end:
getch();
}