← Back to list

8086 Guide: Finding “Hidden” Variables in DOSBox

When writing Assembly, you’ll often find that your program runs perfectly but displays nothing on the screen. This is because the CPU…

Mandipchhetri · 2026-02-18 12:16 · 1 claps · 1.7 min read
#assembly-languagex #x86 #computer-science #dosbox #debugging
Open on Medium ↗
Wiki topics: 💻 · Programming 🔬 · Science · General

8086 Guide: Finding “Hidden” Variables in DOSBox

When writing Assembly, you’ll often find that your program runs perfectly but displays nothing on the screen. This is because the CPU stores the result in a memory location (a variable), but it doesn’t automatically send that data to the monitor.

This guide teaches you how to “interrogate” the RAM to see your results using the DEBUG utility.

1. The Challenge: Adding 1 to 255

We want to add 01H (1) and FFH (255).

  • The Math: $01H + FFH = 0100H$ (Decimal 256).
  • The Problem: Our variable SUM is 16-bit (DW). How do we confirm it holds 0100H?

The Source Code (ADDER.ASM)

TITLE Add two numbers
.MODEL SMALL
.STACK 32
.DATA
    VAL1 DW 0001H
    VAL2 DW 00FFH
    SUM  DW ?        ; We want to check this!
.CODE
MAIN PROC
    MOV AX, @DATA    ; Initialize Data Segment
    MOV DS, AX
    MOV AX, VAL1
    ADD AX, VAL2     ; AX now holds 0100H
    MOV SUM, AX      ; Store result in memory
    MOV AX, 4C00H    ; Exit
    INT 21H
MAIN ENDP
END MAIN

2. Step-by-Step Debugging Process

Step A: Start the Debugger

After assembling and linking your code, load it into the debugger:

Bash

DEBUG ADDER.EXE

Step B: Point to the Data Segment

Before the computer can find your variables, the DS (Data Segment) register must be set.

  • Type -t (Trace) and press Enter.
  • The first instruction MOV AX, @DATA executes.
  • Type -t again.
  • The second instruction MOV DS, AX executes.
  • Now, your program is looking at the correct part of the memory.

Step C: Find the Variable’s Address

We need to know exactly where SUM lives in the RAM.

  • Type -u (Unassemble).
  • Look for the line: MOV [XXXX], AX (where XXXX is a hex number).
  • In our data segment, if VAL1 is at 0000 and VAL2 is at 0002, then SUM is likely at **0004**.

Step D: Execute the Math

You can either keep typing -t to step through line-by-line, or simply type:

-g

This runs the program until the end (INT 21H).

Step E: Dump the Memory (The Result)

Now we look at the address we found in Step C.

Syntax: -d ds:address

-d ds:0004

You will see a display similar to this:

076B:0000 01 00 FF 00 00 01 00 00

3. How to Read the Output

Assembly uses Little Endian format. This means the “Small end” of the number is stored first.

Memory HexInterpretationActual Value00 010100H256 (Our Sum!)01 000001H1 (VAL1)FF 0000FFH255 (VAL2)

💡 Pro Tips

  • The Hyphen: If you see the - prompt, the debugger is waiting for you.
  • The q command: To exit the debugger and go back to the DOS prompt, just type q.
  • Segment check: Always make sure your DS register matches the segment shown in the -d command.

메타데이터
post_id
fba69aeebacb
slug
8086-guide-finding-hidden-variables-in-dosbox-fba69aeebacb
url
https://medium.com/@mandipchhetri/8086-guide-finding-hidden-variables-in-dosbox-fba69aeebacb
canonical_url
https://medium.com/@mandipchhetri/8086-guide-finding-hidden-variables-in-dosbox-fba69aeebacb
author_url
https://medium.com/@mandipchhetri
status
ok
fetched_at
2026-06-14 11:28:49