Aim
To install and configure the DOSBox, MASM, LINK and DEBUG tools to edit, assemble, debug and execute 8086 assembly language programs, and to write and execute a program that adds two 16-bit numbers stored in registers.
Learning objectives
Explain the roles of EDIT, MASM, LINK and DEBUG and the files each produces (.ASM → .OBJ → .EXE).
Mount a host folder as drive C: and run the tools from the DOS prompt.
Write a correct .MODEL SMALL program with .STACK, .DATA, .CODE, a PROC and a DOS exit.
Use ADD and ADC to add two 16-bit numbers and capture the carry.
Use R, T, P, G, D and U to inspect registers, flags and memory.
Interpret CF, ZF, SF, OF, AF and PF after an addition.
What this experiment demonstrates
- How an assembly source file becomes an executable through assembling and linking.
- How the 8086 adds 16-bit values in one instruction, and how the carry out of bit 15 is captured with ADC.
- How a debugger exposes the CPU state after every instruction.
Sub-tasks
- 1.1 Set up the environment (Hello program)
- 1.2 Add two 16-bit numbers in registers
8086 at a glance
The Intel 8086 is a 16-bit microprocessor with a 16-bit data bus and a 20-bit address bus, so it can address 1 MB. Internally it has two units that work in parallel. The BIU fetches instructions into a 6-byte queue and forms addresses. The EU decodes and executes them.
Registers
Fourteen 16-bit registers: four general-purpose registers (AX, BX, CX, DX, each split into high and low bytes), four pointer/index registers (SP, BP, SI, DI), four segment registers (CS, DS, SS, ES), the instruction pointer IP and the FLAGS register.
Segmented memory
Every memory reference uses a segment (a paragraph number) and an offset:
When DOS loads an .EXE, DS and ES point at the PSP (Program Segment Prefix), not at your data. That is why every program begins with MOV AX,@DATA / MOV DS,AX. A segment register cannot be loaded with an immediate value directly.
Development cycle
Source code is typed in an editor, assembled by MASM into a relocatable object file, linked into an executable, and then run or debugged.
| DOSBox command | Effect |
|---|---|
| mount c c:\masm | Make the host folder appear as drive C: |
| c: | Switch to drive C |
| edit prog.asm | Open the editor |
| masm prog; | Assemble → PROG.OBJ (the ; accepts the default file names) |
| link prog; | Link → PROG.EXE |
| debug prog.exe | Load into DEBUG |
DEBUG commands
| Cmd | Meaning | Example |
|---|---|---|
| R | show/modify registers | r · r ax |
| T | trace one instruction | t · t 3 |
| P | proceed over CALL/INT/LOOP | p |
| G | go (run) | g |
| D | dump memory | d ds:0 l10 |
| U | unassemble | u |
| E | enter bytes | e ds:0 34 12 |
| Q | quit | q |
16-bit addition
The result of a 16-bit addition can need 17 bits. The 17th bit goes to CF, and ADC CX,0 (or JC) captures it.
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)
- Install DOSBox. Copy MASM.EXE, LINK.EXE, DEBUG.EXE and EDIT.COM into a folder such as
C:\MASM. - Start DOSBox and type
mount c c:\masm, thenc:. - Type
edit prog.asm, enter the program, save it (Alt-F, S) and exit. - Assemble:
masm prog;. Read the error count. Fix any errors and repeat. - Link:
link prog;. Note the L4021 warning if there is no stack segment. - Load into the debugger:
debug prog.exe. Typerto see the registers. - Trace with
tuntil the ADD executes. Note AX, CF, ZF and the other flags. - Run to the end with
g("Program terminated normally"), thenq. - Repeat with operands that produce a carry (e.g. 0F000H + 2000H) and record both results.
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
- Assemble before mounting drive C. What does DOSBox say?
- Remove
MOV DS,AXfrom the Hello program. What gets printed, and why? - Remove the
$terminator from the message. - Delete the last two lines (
MOV AH,4CH/INT 21H). What does the simulator report? - Use 0F000H + 2000H: check CF and CX.
- Use 7FFFH + 0001H: CF = 0 but OF = 1. Explain why.
- Write
MOV AX, FFFFH(no leading 0) and read the MASM error.
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.