1

I have instruction MOV label, HL. I only understand the first row, but second I don't, if it's only instruction MOV label, HL, why do we always need to get the address for low and high values of label? What is ZR?

And can someone explain to me those rows with execute.

Click here to see tabele

Alexis Wilke
  • 19,179
  • 10
  • 84
  • 156
Rahul
  • 5
  • 3
  • 3
    `zr` is presumably an internal temporary register. The address of label (2 bytes) is encoded in the instruction, which is fetched into `zr` and subsequently used as memory address. – Jester Jan 16 '16 at 19:29
  • 1
    Do you mind sharing your source? – GabrielOshiro Jan 17 '16 at 08:04
  • I'd love to see the source too. Deutsch ist kein Problem. – Tommy Jan 18 '16 at 16:28
  • Based on the questioner's second question, which concerns the MC8, and a Google search for the MC8, it's likely she's taking Digital Systems at Technische Universität Wien and therefore, I guess, that this information comes from the course materials for that. I could find only a couple of pieces of externally available information related to that class, the papers "Watching a Processor at Work" and "Assembler Through The Looking Glass: Understanding Digital Systems", neither of which contain any substantial z80 documentation. – Tommy Jan 20 '16 at 19:50

1 Answers1

1

This table looks like a definition of what the instruction (code 22h) does when the CPU executes it. So the instruction, in whole, has 5 steps to execute the whole process. To you, as a programmer, it still looks like just one instruction.

Z80 is an old 8 bit technology and at the time we could not read 64 bits at once (or even more with caches of today). So each read or write to the memory was one step and one byte at a time.

The table explains what is happening on each step. This is particularly important if you are trying to build a computer with that CPU. However, it is much less important if you are programming the chip unless you do something that includes timing that needs to be correct to the cycle.

So the MOV label, HL would move 16 bits from memory at address label to the register HL.

(1) First the processor reads one byte at PC and finds out that the instruction is 22h. Ah! That's a MOV label, HL.

(2,3) The process now knows it has to read two more bytes from PC, representing a memory address. Z80 being a little endian, it first reads the low byte (from PC + 1) and then the high byte (from PC + 2).

(4,5) The address loaded with step (2,3) is now in a temporary register (internal CPU buffer called ZR) and is used to read two bytes from memory. These two bytes are saved in the HL register. HL means High and Low bytes. So the byte at ZR is loaded in L and the byte at ZR + 1 is loaded in H (again, we are loading the register in little endian).

Note: PC will end up being incremented by 3 and is possibly increment by one each time it is used to read one byte.

So it loads the contents of the HL double register at once from a memory buffer specified by label (a hard coded address in the 64Kb addressable memory.)

For example, if you start with HL set to 0x0000 and you have the instruction:

MOV 0x2345, HL

and at address 0x2345 you have byte 0x12
and at address 0x2346 you have byte 0x56

then HL ends up being: 0x5612.

And the instruction will be encoded as: 0x22 0x45 0x23

Alexis Wilke
  • 19,179
  • 10
  • 84
  • 156
  • 1
    Possibly also of relevance: the z80's distinction between a machine cycle and a clock cycle. If you were building a machine you'd probably also care about the refresh cycles, which the table doesn't list, but which are independent of the instruction stream (unless one of those instructions is to load R, of course). – Tommy Jan 18 '16 at 16:31