Tag Archives: 8086

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.

Continue reading 8086 Assembly Program for Division of Two 8-bit Numbers

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.

Continue reading 8086 Assembly Program to Add Two 32-bit Numbers

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.

Continue reading 8086 Assembly Program to Multiply Two 32-bit Numbers

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.

Continue reading 8086 Assembly Program for Subtraction of Two 32-bit Numbers

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.

Continue reading 8086 Assembly Program to Multiply Two 16-bit Numbers

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.

Continue reading 8086 Assembly Program to Subtract Two 16-bit Numbers

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.

Continue reading 8086 Assembly Program to Divide Two 16-bit Numbers