This program demonstrates how to use inline 8086 assembly in C++ to determine whether a given number is positive or negative. It’s a great way to understand how conditional branching works at the assembly level.
#include<iostream.h>
#include<conio.h>
void main() {
clrscr();
int a;
cout << "\n Enter a number:";
cin >> a;
asm mov ax, 0000h // Clear AX
asm mov ax, a // Move user input into AX
asm cmp ax, 0000h // Compare AX with 0
asm jl less // Jump to 'less' if AX < 0
asm jge greater // Jump to 'greater' if AX >= 0
less:
cout << "\n Number is negative";
asm jmp end
greater:
cout << "\n Number is positive";
end:
getch();
}