Skip to main content

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.

8086 Assembly Program for Division of Two 8-bit Numbers

8-bit division in 8086 assembly has a subtle but important difference from 16-bit division: the dividend is always the full 16-bit AX register, not just AL. When you write DIV b with a byte operand, the CPU divides the 16-bit value in AX by that byte — quotient lands in AL, remainder in AH. Getting AH cleared to zero before the divide is therefore essential for a correct result. This post walks through a working implementation in three environments: MASM/TASM, emu8086, and NASM.

8086 Assembly Program to Add Two 32-bit Numbers

Adding two 32-bit numbers on the 16-bit 8086 requires two passes: first add the lower 16-bit words, then add the upper 16-bit words using ADC (Add with Carry) to fold in any carry from the first pass. The carry propagation between the two halves is what makes multi-word arithmetic correct — skip it and the upper half of your result will be wrong whenever the lower addition overflows. This post walks through a working implementation in three environments: MASM/TASM, emu8086, and NASM.

8086 Assembly Program to Multiply Two 32-bit Numbers

Multiplying two 32-bit numbers on the 16-bit 8086 is the most involved of the basic arithmetic operations. Because the processor only has a 16×16 → 32 multiplier, a 32×32 multiplication must be broken into four 16×16 partial products and their results accumulated with careful carry propagation. The final 64-bit result spans eight bytes across four 16-bit words. This post walks through a working implementation in three environments: MASM/TASM, emu8086, and NASM.

8086 Assembly Program for Subtraction of Two 32-bit Numbers

Subtracting two 32-bit numbers on the 16-bit 8086 uses the same two-pass approach as 32-bit addition, but with SBB (Subtract with Borrow) instead of ADC. The first pass subtracts the lower 16 bits with SUB; if that produces a borrow (CF=1), the second pass uses SBB to subtract the upper 16 bits and the borrow together. This post walks through a working implementation in three environments: MASM/TASM, emu8086, and NASM.

8086 Assembly Program to Multiply Two 16-bit Numbers

Multiplication in 8086 assembly has one important difference from addition and subtraction: you do not choose the destination. The MUL instruction always multiplies the implicit register AX by the operand you supply, and always puts the 32-bit result into DX:AX. Understanding that implicit contract — and always saving both halves of the result — is the key to correct multiplication programs. This post walks through a working implementation in three environments: MASM/TASM, emu8086, and NASM.

8086 Assembly Program to Subtract Two 16-bit Numbers

Assembly language offers a hands-on approach to understanding how computers perform basic arithmetic at a low level. Subtraction in 8086 assembly follows the same register-first pattern as addition — but with one extra detail worth getting right: operand order. SUB AX, BX computes AX − BX, not BX − AX. Getting that backwards produces a wrong result with no assembler warning. This post walks through a working implementation in three environments: MASM/TASM, emu8086, and NASM.

8086 Assembly Program to Divide Two 16-bit Numbers

Division in 8086 assembly is the most instruction-constrained of the four arithmetic operations. Unlike addition or subtraction, the DIV instruction does not let you choose which registers hold the dividend and quotient — the hardware fixes those roles permanently. Understanding why the registers are wired this way is the key to writing correct division programs and avoiding the dreaded divide overflow exception. This post walks through a working implementation in three assembler environments: MASM/TASM, emu8086, and NASM.