0

I'm curently starting to learn Z80 assembly language and I have the following snipet of code :

LD A, 53H
LD B, F5H
ADD A, B
halt 

It simply loads two immediates into the registers A and B, and adds them up.

The problem I have is with the sencond line containing LD B, F5H. The assembler is complaining about undefined variable: F5H Line: 2 with one assembler and Invalid argument of the instruction using a different assembler.

Can someone explain what syntax error I'm doing here? the first line compiles with no errors.

Strangely, using the interactive assembly writer, doing LD B, 0F5H seems to fix the error, whereas in the first line, writing either LD B, F5H orLD B, 0F5H is fine, and both generate the same object code.

From the Z80 manual :

Upon the execution of an LD E, A5h instruction, Register E contains A5h.

Thanks in advance.

Ait-Gacem Nabil
  • 165
  • 3
  • 12
  • 5
    Since `F` is a letter, the assembler thinks `F5H` a symbol. Numbers should begin with a digit, no matter the base, to avoid confusion. That is why `0F5H` works. Note this depends on assembler. – Jester Jun 15 '22 at 20:58
  • I really had a dumb moment thinking about how ```B``` register is coded as ```b'000```and confusing it with a ```halt``` insruction which is ```b'0000``` on this platform or something like that. Thank you for your help. – Ait-Gacem Nabil Jun 15 '22 at 21:02
  • The documentation was misleading as well. – Ait-Gacem Nabil Jun 15 '22 at 21:05
  • 1
    Same reason as in all assemblers that use trailing-h to indicate hex (instead of a leading `$` or `0x`), like Jester said, so basically a duplicate of [Leading zeros in hex values](https://stackoverflow.com/q/58061348) and [How do I write letter-initiated hexadecimal numbers in masm code?](https://stackoverflow.com/q/33276232) – Peter Cordes Jun 16 '22 at 01:03
  • @PeterCordes I disagree on it being a duplicate but the linked question is indeed helpful. Thanks everyone. – Ait-Gacem Nabil Jun 16 '22 at 06:52
  • 1
    It's not an *exact* duplicate, but the answer there answers this question. Basics like this don't really need separate answers for each circumstance in which confusion happened, so my threshold for how close a question has to be is lower than for trickier concepts. – Peter Cordes Jun 16 '22 at 06:54

0 Answers0