Z80 Registration Endianness

Given this code example:

ZilogZ80A cpu = new ZilogZ80A(); cpu.GeneralRegisters.H.FromUInt(229); cpu.GeneralRegisters.L.FromUInt(90); Console.WriteLine("H : " + cpu.GeneralRegisters.H.ToString()); Console.WriteLine("L : " + cpu.GeneralRegisters.L.ToString()); Console.WriteLine("HL: " + cpu.GeneralRegisters.HL.ToString()); Console.WriteLine("Load 23268 (0x5AE4) into register HL..."); cpu.GeneralRegisters.HL.FromUInt(23268); Console.WriteLine("H : " + cpu.GeneralRegisters.H.ToString()); Console.WriteLine("L : " + cpu.GeneralRegisters.L.ToString()); Console.WriteLine("HL: " + cpu.GeneralRegisters.HL.ToString()); 

Which does the following:

  • Load 229 (decimal) into register H
  • Load 90 (decimal) into register L
  • Print the values โ€‹โ€‹(hexadecimal, binary MSB, decimal) of the registers H, L and HL
  • Load 23268 (decimal) into the HL register
  • Print the values โ€‹โ€‹of the registers H, L and HL again.

Output Example:

 H : 08-bit length register (@45653674): 0x00E5 | MSB 0b11100101 | 229 L : 08-bit length register (@41149443): 0x005A | MSB 0b01011010 | 90 HL: 16-bit length register (@39785641): 0x5AE5 | MSB 0b01011010 11100101 | 23269 Load 23268 (0x5AE4 into register HL... H : 08-bit length register (@45653674): 0x00E4 | MSB 0b11100100 | 228 L : 08-bit length register (@41149443): 0x005A | MSB 0b01011010 | 90 HL: 16-bit length register (@39785641): 0x5AE4 | MSB 0b01011010 11100100 | 23268 

Now for the questions:

  • Are the above assumptions (and sample output) the correct register functions?
  • Do other register pairs (AF, BC, DE) do the same?
  • If the answer is 1. and 2. yes, why is the Z80 then considered a little endian? When the contents of the HL register are written into memory, the first byte goes first, but (by reading them sequentially after that, the bytes are certainly in ascending order)?
+6
source share
2 answers

Yes - HL consists of H as the most significant byte, L as the least. If you perform a 16-bit operation of the type ADD HL,BC , then the transfer from the upper bit L+C will go to the calculation of H+B In this regard, all pairs of the register are the same.

The fact that things of a logical order are written is not related to entiance. For instance. in C you do not need to write 0x0001 on some platforms equal to 0x0100 on others. When you write, you write the most significant first.

Z80 is unimportant, because if you have to store HL in memory, L will write bytes to H If you want to read, L will be counted from address to H

+9
source
 ld hl, $1234 ld ($fc00), hl 

At this point, H = $ 12, L = $ 34, as your code shows. The byte is $ fc00 = $ 34, and the byte is $ fc01 = $ 12. So, if you subsequently do:

 ld hl, $5678 ld ($fc02), hl 

($ fc00) = $ 34, ($ fc01) = $ 12, ($ fc02) = $ 78, and ($ fc03) = $ 56. Thus, reading a byte from a byte from $ fc00 will cost $ 34127856 instead of $ 12345678, because the Z80 is a bit oriented.

+3
source

All Articles