Skip to main content

MP

Mix (C++ and Assembly) Program to Subtract Two 8 bit Numbers

While modern high-level languages like C++ abstract away many low-level operations, sometimes it's useful to get closer to the hardware to understand how things work under the hood. This example demonstrates how to subtract two 8-bit numbers using inline assembly in a simple C++ program. #include<iostream.h> #include<conio.h> #include<stdio.h> void main() { clrscr(); short int a, b, c; cout << "Enter First Number:"; cin >> a; cout << "Enter Second Number:"; cin >> b; asm mov ax, a // Move 'a' into AX asm mov ah, 00h // Ensure AH is cleared asm mov bx, b // Move 'b' into BX asm mov bh, 00h // Ensure BH is cleared asm sub al, bl // Subtract BL from AL asm mov c, ax // Store result in 'c' cout << "Result:"; cout << c; getch(); }

8086 Assembly Program to Search an Element in an Array

Array search is where assembly starts feeling like real programming — you need a pointer, a counter, a comparison, and a conditional branch, all working together. This program searches a five-element byte array for a target value and prints either “FOUND” or “NOT FOUND” using a reusable MACRO that wraps the DOS print call.

Mix (Assembly and C++) Program to Find Greatest of Two Numbers

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(); }

8086 Assembly Program to Print ‘hello’ using 09H

DOS interrupt 21h function 09h is the easiest way to print a string in 8086 assembly: point DX at your string, set AH to 09h, call INT 21h, and you’re done. No loop, no character counter, no BX pointer arithmetic. The tradeoff is a minor convention: the string must end with a $ character so DOS knows where to stop. Compare this with the function 02h character loop approach — 09h is cleaner for fixed strings; 02h gives you more control for dynamic output.

Interrupting BIOS with 8086 Assembly Program

INT 10h is the BIOS video interrupt — completely separate from the DOS INT 21h family. Where INT 21h talks to the operating system, INT 10h talks directly to the video BIOS to control the screen: cursor shape, cursor position, character output, screen modes. This short program demonstrates two of those functions: setting the cursor shape and moving it to a specific screen position.

Mix Program in Assembly and C++ to Find Factorial of Number

This C++ program calculates the factorial of a number between 0 and 8 using inline 8086 assembly instructions. The multiplication is handled within an assembly loop, showcasing a basic yet insightful use of mul, dec, and jnz instructions. #include<iostream.h> #include<conio.h> void main() { clrscr(); short a; unsigned int c; cout << "\n Enter Number between 0 to 8:"; cin >> a; asm mov ax, 0000h asm mov al, 01h // Initialize AX to 1 asm mov cx, 0000h asm mov cx, a // Set CX loop counter to input value bac: asm mul cx // Multiply AX by CX asm dec cx // Decrement CX asm jnz bac // Loop until CX reaches zero asm mov c, ax // Move result from AX to variable c cout << "\n Factorial of " << a << " is " << c; getch(); }

Implementing JUMP, PUSH, POP, IN & OUT in Assembly Program on 8086

This program is a sandbox for five instructions you’ll encounter constantly in real 8086 code: unconditional jump (JMP), stack push and pop, and port I/O (IN/OUT). Rather than demonstrating each in isolation, the program weaves them together into a two-iteration loop that modifies variables, saves and restores registers through the stack, then reads from and writes to an I/O port at the end. It’s a useful reference for anyone trying to understand how these instructions interact.

8086 Assembly Program to Display String ‘hello’

There are two ways to print a string in 8086 DOS assembly. One is the clean, one-call approach using INT 21h function 09h. The other — shown here — is the character-by-character loop using function 02h. It’s more verbose, but it gives you a clear picture of how string output actually works at the hardware level: load a character into DL, call INT 21h, move to the next character, repeat. Once you understand this version, the shortcut function 09h makes a lot more sense.

8086 Assembly Program for Subtraction of Two 8-bit Numbers

8-bit subtraction on the 8086 follows the same register-first pattern as 16-bit subtraction — but with one extra gotcha to watch: because only AL is involved in the computation, AH retains whatever value it had from the segment setup code. When you later store the full AX into the result variable, that dirty AH comes along for the ride. The emu8086 and NASM versions below fix this with a single xor ah, ah. This post walks through a working implementation in three environments: MASM/TASM, emu8086, and NASM.

8086 Assembly Program for Multiplication of Two 8-bit Numbers

8-bit multiplication on the 8086 is simpler than its 16-bit counterpart in one important way: the result always fits in a single register pair. MUL with an 8-bit operand multiplies the implicit AL register by that operand and places the full 16-bit result in AX — no separate DX needed. This post walks through a working implementation in three environments: MASM/TASM, emu8086, and NASM.