Skip to main content
  1. Blogs/

The Parable of The Smart Forgetful Mayor

programming 8086 assembly lesson programming
Philip Peh
Author
Philip Peh

The Parable of The Smart Forgetful Mayor

I think this is exactly the right way to teach assembly.

Most students fail because they learn:

MOV
ADD
SUB
AX
BX

as vocabulary.

What they need is a world they can imagine.


The City of 1,048,576 Houses
#

Long ago there was a vast city.

Not a city of people.

A city of houses.

Exactly:

1,048,576 houses

Every house had an address:

00000h
00001h
00002h
...
FFFFFh

Each house was tiny.

A house could store only one thing:

1 byte

No more.

No less.

The city was called Memory.


The Mayor
#

At the center of the city lived a very fast mayor.

The mayor was the 8086 CPU.

The mayor could think quickly.

But he had a problem.

He had a terrible memory.

He couldn’t remember a million houses.

He only had a small desk.

On that desk were a few drawers:

AX
BX
CX
DX

These drawers were called registers.

The mayor used them for all his work.


The Messenger
#

The mayor never wandered around the city randomly.

He always followed instructions.

A messenger named IP (Instruction Pointer) carried a map.

The map always pointed to:

“The next instruction to execute.”

Whenever the mayor finished a task, the messenger moved to the next address.


The Story of Adding Two Numbers
#

One day the city received a request:

Add 5 and 3.

The request was stored inside several houses.

If we looked using DEBUG’s code viewer:

-u 100

we might see:

MOV AX,5
MOV BX,3
ADD AX,BX

To humans this is easy.

But the mayor cannot read English.


What the Mayor Actually Sees
#

The houses actually contain:

B8 05 00
BB 03 00
01 D8

These are machine-code bytes.

If we use:

-d 100

we see the actual contents of the houses.

Like this:

0100 B8
0101 05
0102 00
0103 BB
0104 03
...

The houses never contain:

MOV AX,5

They contain bytes.

The mayor only understands bytes.


DEBUG the City Inspector
#

Now imagine a city inspector arrives.

His name is DEBUG.

DEBUG can do things ordinary citizens cannot.

He can:

  • Open houses
  • Read houses
  • Change houses
  • Watch the mayor work
  • Stop the mayor
  • Ask what is in the mayor’s desk

Every command in DEBUG is one of the inspector’s tools.


D — Open the Houses
#

When DEBUG says:

-d 100

he is saying:

Show me the houses starting at address 0100.

Like opening a street map.

House 0100: B8
House 0101: 05
House 0102: 00
...

You are not seeing instructions.

You are seeing the contents of houses.


U — Translate the Houses
#

The inspector also speaks Machine.

When he uses:

-u 100

he reads the same houses and says:

Ah! These bytes mean MOV AX,5.

So:

D = Show houses
U = Translate houses

Same neighborhood.

Different view.


R — Open the Mayor’s Desk
#

The mayor has drawers.

When we type:

-r

DEBUG opens the desk.

We can see:

AX=0000
BX=0000

or later:

AX=0008

The work isn’t stored in the city.

It’s currently sitting on the mayor’s desk.


T — Follow the Mayor One Step
#

Suppose we say:

-t

The inspector follows the mayor.

Just one step.

The mayor reads:

MOV AX,5

and places:

5

into drawer AX.

The inspector watches.

Nothing is hidden.


Another T
#

Again:

-t

The mayor reads:

MOV BX,3

and places:

3

into drawer BX.

Now the desk looks like:

AX = 5
BX = 3

The Important Moment
#

One more:

-t

The mayor reaches:

ADD AX,BX

He opens drawer AX.

5

He opens drawer BX.

3

He adds them.

8

He puts the result back into AX.

Now:

AX = 8
BX = 3

The city hasn’t changed.

The houses haven’t changed.

Only the contents of the mayor’s desk changed.

This is a huge realization for students.


G — Let the Mayor Work
#

Following every step is tiring.

Instead we can say:

-g

Which means:

Go.

The inspector steps aside.

The mayor works continuously until finished.


E — Renovate a House
#

Suppose house 0101 contains:

05

The inspector can change it.

-e 101

Now it becomes:

0A

Suddenly:

MOV AX,5

becomes:

MOV AX,10

The program changed because a house changed.


A — Writing New Laws
#

The city council can create new instructions.

Using:

-a 100

we write:

MOV AX,5
MOV BX,3
ADD AX,BX

DEBUG translates them into machine-code bytes and stores them into houses.

The council writes laws.

The houses store them.

The mayor obeys them.


The Secret of the Whole City
#

At first students think:

Program = instructions

But after DEBUG they discover:

Program
=
Bytes in houses

The CPU never sees:

ADD AX,BX

The CPU only sees bytes.

DEBUG is magical because it lets us see both worlds:

Human World
MOV AX,5

Machine World
B8 05 00

and it lets us walk back and forth between them.


The Moral of the Story
#

The City has 1,048,576 houses.

The Mayor has a tiny desk.

The Messenger points to the next task.

The Houses store bytes.

The Mayor executes bytes.

DEBUG is the Inspector who lets us see everything.

Once students understand this story, every DEBUG command stops feeling like a command to memorize and starts feeling like a natural action in a living city:

D = Open houses
U = Translate houses
R = Open the mayor's desk
E = Renovate houses
A = Write new laws
T = Follow the mayor
G = Let the mayor work

And that is essentially the entire first lesson of 8086 assembly.

Additional Story Graphic

Additional Comic 1

Additional Comic 2

Written and translated with the assistance of AI tools.