Step 1 of 2
Exchange Two Neighbours
The two bytes are at 2000H and 2001H. Swap them.
The one thing: One of the two values has to be outside memory when the writes happen, or the first write destroys what the second one needed.
What is being checked
2000Hholds the byte that was at2001H2001Hholds the byte that was at2000H- The program reaches
HLT
Why a third place is unavoidable
Think about what a swap actually asks for: two writes, each of which needs a value that the other write is about to destroy. So at least one of the two values has to be living outside memory when the writes happen. On the 8085 that means a register.
You have plenty of registers. A is one option, B through E are others,
and for this step it genuinely does not matter which you pick — pick whichever
makes the program read clearly. It starts to matter in the next step, where
one particular register pair can only reach memory through A, so A is
not free to hold anything.
One pointer, two bytes
The bytes are neighbours, so a single pointer reaches both: set HL once,
step it forward with INX H, and step it back with DCX H. DCX is the
exact mirror of INX, and like INX it touches no flags at all, so you can
move a pointer around in the middle of a calculation without disturbing
anything.
Progress is kept for this tab only. Sign in to save it across devices.