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
State which registers MUL and DIV use implicitly (AL/AX, AX/DX:AX).
Explain why an n×n-bit product needs 2n bits and where each half is stored.
Locate the quotient and the remainder after 16÷8 and 32÷16 division.
Predict when DIV raises a divide-overflow (INT 0) exception, and prevent it.
Distinguish MUL/DIV from IMUL/IDIV.
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
Worked examples
Divide overflow
For DIV src8 the quotient must fit in AL (≤ FFH). This is true only when AH < divisor before the division.
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
| Item | Specification | Qty |
|---|---|---|
| Computer | Windows / Linux / macOS PC | 1 |
| DOSBox | 0.74-3 (DOS emulator) | — |
| MASM | Microsoft Macro Assembler 5.10 (MASM.EXE) | — |
| LINK | Overlay Linker 3.64 (LINK.EXE) | — |
| DEBUG | DOS DEBUG.EXE | — |
| Editor | EDIT.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
10as decimal and10Has 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)
- Enter the program in EDIT, assemble and link.
- In DEBUG, use
d ds:0to see the operands. - Trace to the MUL/DIV instruction. Note AX (and DX) before and after.
- Check CF/OF after MUL: they are 1 when the upper half is non-zero.
- Run to completion and dump the results.
- Repeat with a divisor that causes divide overflow, observe the message, then fix the program.
Doing it in this virtual lab
- Pick a sub-task chip. Its program opens in the blue EDIT window.
- Press Assemble + Link (F7). Errors appear in red: click one to jump to the line.
- Press Step (T) (F8) to execute one instruction at a time. Watch the registers, flags and memory change, and read the Operation panel.
- 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. - 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-task | Inputs | Expected | Simulator | Your value | Check | Note |
|---|
Edge cases to test
- 3.3 with DVS = 02H: divide overflow. Why? Fix it by using a 16-bit divisor (
XOR DX,DX/DIV BX). - 3.3 with DVS = 00H: divide by zero.
- Write
MUL 10: what does MASM say? - Write
MUL [SI]without BYTE PTR or WORD PTR. - 3.1 with FFH × FFH: check CF/OF.
- 3.2 with 0001H × 1234H: why is DX = 0 and CF = 0?
Analysis & conclusion
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.
Self-evaluation
Tick what you can now do confidently.