×÷
MPMC Lab · Experiment 3 · 8086 · MUL/DIV

Multiplication and Division (8086)

8×8 and 16×16 unsigned multiplication and 16÷8 division with operands in memory.

☰ All experiments

Aim

To write and execute 8086 assembly programs that multiply two 8-bit numbers and two 16-bit numbers, and divide a 16-bit number by an 8-bit number, with the operands stored in memory.

Learning objectives

1
Implied operands
State which registers MUL and DIV use implicitly (AL/AX, AX/DX:AX).
2
Product width
Explain why an n×n-bit product needs 2n bits and where each half is stored.
3
Division results
Locate the quotient and the remainder after 16÷8 and 32÷16 division.
4
Divide overflow
Predict when DIV raises a divide-overflow (INT 0) exception, and prevent it.
5
Signed vs unsigned
Distinguish MUL/DIV from IMUL/IDIV.
6
Verification
Verify products and quotients by hand and in DEBUG.

What this experiment demonstrates

  • Hardware multiplication and division in a single instruction (the 8085 had none).
  • How results larger than one register are split across AH:AL or DX:AX.
  • The divide-overflow exception: a real run-time error.

Sub-tasks

  • 3.1 Multiply two 8-bit numbers (memory)
  • 3.2 Multiply two 16-bit numbers (memory)
  • 3.3 Divide a 16-bit number by an 8-bit number

MUL and DIV

MUL (unsigned) AL×src8=AX AX×src16=DX : AX DIV (unsigned) AX÷src8→AL=q AH=r DX:AX÷src16→AX=q DX=r • The other operand is implied: AL/AX. The source can be a register or memory, never an immediate (MUL 5 is illegal). • MUL sets CF = OF = 1 when the upper half (AH or DX) is non-zero. • DIV raises INT 0 "Divide overflow" if the divisor is 0 or the quotient does not fit in AL/AX (e.g. 1000H ÷ 2 = 800H > FFH). • Before a 16 ÷ 8 divide the dividend must be in AX; before 32 ÷ 16 put the high word in DX (clear DX for a 16-bit dividend).
Fig 5. Implied operands of MUL and DIV.

Worked examples

8 × 8 : A5H × 3CH = 26ACH → AX = 26ACH (AH = 26H, AL = ACH) 16 × 16: 1234H × 5678H = 0626 0060H → DX = 0626H, AX = 0060H 16 ÷ 8 : 1A2BH ÷ 45H = 61H rem 06H → AL = 61H (quotient), AH = 06H (remainder) Check : 61H × 45H + 06H = 1A25H + 06H = 1A2BH ✓

Divide overflow

For DIV src8 the quotient must fit in AL (≤ FFH). This is true only when AH < divisor before the division.

AX = 1000H, divisor = 02H → quotient 800H > FFH → INT 0 → DOS prints "Divide overflow"

For a large dividend use a 16-bit divisor: XOR DX,DX, then DIV BX.

Signed versions

IMUL and IDIV treat operands as two's complement. CBW (AL→AX) and CWD (AX→DX:AX) sign-extend the dividend before IDIV.

Apparatus & environment

ItemSpecificationQty
ComputerWindows / Linux / macOS PC1
DOSBox0.74-3 (DOS emulator)—
MASMMicrosoft Macro Assembler 5.10 (MASM.EXE)—
LINKOverlay Linker 3.64 (LINK.EXE)—
DEBUGDOS DEBUG.EXE—
EditorEDIT.COM or any text editor—

Safety rules & good practice

  • 💾 Keep your .ASM files in the mounted folder (e.g. C:\MASM) and save often. DOSBox does not autosave.
  • 🧭 Never assemble system files or run unknown .EXE files inside the lab folder.
  • ⌨ Use Ctrl+F9 to close a hung DOSBox and Ctrl+F10 to release the mouse.
  • 🧮 Check the number base: MASM treats 10 as decimal and 10H as hex. Hex constants must start with a digit (0FFH).
  • 🛑 Always end an .EXE with MOV AH,4CH / INT 21H. Without it the CPU runs into garbage and DOSBox may hang.

Procedure (hardware / real tools)

  1. Enter the program in EDIT, assemble and link.
  2. In DEBUG, use d ds:0 to see the operands.
  3. Trace to the MUL/DIV instruction. Note AX (and DX) before and after.
  4. Check CF/OF after MUL: they are 1 when the upper half is non-zero.
  5. Run to completion and dump the results.
  6. Repeat with a divisor that causes divide overflow, observe the message, then fix the program.
Click a step to tick it off. Your progress is saved in this browser.

Doing it in this virtual lab

  1. Pick a sub-task chip. Its program opens in the blue EDIT window.
  2. Press Assemble + Link (F7). Errors appear in red: click one to jump to the line.
  3. Press Step (T) (F8) to execute one instruction at a time. Watch the registers, flags and memory change, and read the Operation panel.
  4. Or open the DOS prompt tab and type the real commands: mount c c:\masm, c:, masm prog;, link prog;, debug prog.exe, r, t, d ds:0, g, q.
  5. Change the input values in the Inputs card (the program text updates), run again, and press ● Record.

Pre-Lab Test 6 questions · diagnostic

Check your prerequisite knowledge. Each answer gets instant feedback. Score at least 4/6 before using the simulator.

Observation table

Rows are added by ● Record in the simulator: inputs, the expected (theoretical) value and the simulator result. Type your own hand calculation in "Your value" to check it. Add rows by hand for hardware-bench readings. The table is saved in this browser.

#Sub-taskInputsExpectedSimulatorYour valueCheckNote

Edge cases to test

  1. 3.3 with DVS = 02H: divide overflow. Why? Fix it by using a 16-bit divisor (XOR DX,DX / DIV BX).
  2. 3.3 with DVS = 00H: divide by zero.
  3. Write MUL 10: what does MASM say?
  4. Write MUL [SI] without BYTE PTR or WORD PTR.
  5. 3.1 with FFH × FFH: check CF/OF.
  6. 3.2 with 0001H × 1234H: why is DX = 0 and CF = 0?

Analysis & conclusion

Saved automatically in this browser.

Post-Lab Test 9 questions · instant hints

A wrong answer shows a hint so you can try again. Only first attempts count towards the score.

9. Numerical: AL = 0C8H, BL = 0AH. After MUL BL, what is AX (hex)?

Self-evaluation

Tick what you can now do confidently.

Overall confidence:

Feedback summary

Finish the post-lab test to see your personalised summary.