Aim
To write and execute 8086 programs that transfer a block of N bytes/words, find the smallest and largest numbers in an array, and count the number of 0s and 1s in a byte.
Learning objectives
Use SI/DI/BX as pointers with [SI], [DI] and [BX+SI].
Control loops with CX and the LOOP instruction.
Use MOVSB/MOVSW with REP, CLD/STD, and set ES correctly.
Use CMP with JA/JB/JAE/JBE (unsigned) and JG/JL (signed).
Shift or rotate bits into CF and count them.
Handle an array of length 1, overlapping blocks and equal elements.
What this experiment demonstrates
- Pointer-based processing of arrays, the core of any data handling.
- The 8086 string instructions that copy a whole block with one REP prefix.
- Shifting bits through the carry flag to examine them one at a time.
Sub-tasks
- 4.1a Block transfer of N bytes (REP MOVSB)
- 4.1b Block transfer of N words (loop)
- 4.2 Smallest and largest number in an array
- 4.3 Count the 0s and 1s in a byte
Addressing modes
| Mode | Example | Effective address |
|---|---|---|
| Direct | MOV AL,ARR | offset of ARR |
| Register indirect | MOV AL,[SI] | SI |
| Based/indexed + disp | MOV AL,ARR[SI] | ARR + SI |
| Based indexed | MOV AL,[BX+SI] | BX + SI |
Only BX, BP, SI and DI can appear inside brackets. BP defaults to the stack segment SS.
String instructions
Finding min / max
Use JA/JB for unsigned data and JG/JL for signed data. As a signed value, 0F0H is −16, so the "largest" element changes.
Counting bits
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, assemble and link.
- In DEBUG, dump the source block or array with
d ds:0. - Trace through one or two loop iterations with
t, watching SI, DI, CX and the flags. - Use
pto step over a wholeREP MOVSBor LOOP. - Run to completion with
gand dump the results. - Change the data (array values, N) and repeat. Record each run.
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
- 4.1a without
MOV ES,AX. Where did the bytes go? - 4.1a with STD instead of CLD (and SI/DI unchanged). What happens?
- 4.2 with a single-element array (N − 1 = 0, so CX = 0 → LOOP runs 65536 times!). Guard with JCXZ.
- 4.2 with all elements equal.
- 4.2 with 0F0H in the array: compare JAE/JBE with JGE/JLE.
- 4.3 with 00H and 0FFH.
- 4.1b: replace ADD SI,2 with INC SI. What goes wrong?
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.