Step 2 of 2
Swap Bytes That Are Far Apart
Now the two bytes are nowhere near each other: one at 2000H and one at
3000H. Swap them, using a pointer for each.
The one thing:
DEcan hold an address, but every byte going in or out of it has to pass throughA.
What is being checked
2000Hholds the byte that was at3000H3000Hholds the byte that was at2000H- The program reaches
HLT - You reach memory through the pointers, and not with
LDAorSTA
Why LDA and STA are ruled out here
They would work. Both addresses are fixed, so LDA 3000H / STA 2000H is a
perfectly good three-line answer, and by the rule of thumb from the previous
problem it is even the right tool for two fixed addresses.
The reason this step insists on pointers anyway is that these two addresses
are about to start moving. In the block-copy and sorting problems the source
and destination advance on every pass of a loop, and at that moment LDA and
STA become useless — the address is baked into the instruction and there is
no way to change it. Getting the two-pointer shape into your fingers now, on a
problem simple enough to check by eye, is the whole point.
DE is a pointer with one narrow door
HL is privileged. It has M, which lets any MOV read or write the byte it
points at: MOV B, M, MOV M, C, and so on.
BC and DE have no such thing. They can hold an address, but the only way
through is the accumulator:
LDAX D— loadAfrom the byteDEpoints atSTAX D— storeAinto the byteDEpoints at
That single narrow door is what shapes the program. A is permanently busy
ferrying bytes to and from DE, so the byte you lift out of HL's location
has to wait in some other register while A does its work.
Progress is kept for this tab only. Sign in to save it across devices.