8

Recently I have been trying to compile CP/M 2.2 from source. When I try to assemble, everything works except for the instructions ADD A,M and SBC A,M, which the assembler returns a syntax error. I have not done much Z80, so I am a little confused on what the source code means by M?

I am using the CP/M 2.2 Source (Z80 Mnemonics) from the Unofficial CP/M Website.

4
  • 2
    It might be helpful if you link the source in question and explain where you acquired it.
    – Raffzahn
    Dec 14, 2018 at 1:55
  • 2
    without seeing the code we can only guess if it means (HL) memory access or direct 8/16 bit constant N or NN... but my bet is the (HL). It also could be some Macro
    – Spektre
    Dec 14, 2018 at 8:02
  • 2
    LD A,M is actually 8080 syntax, not Z80.
    – tofro
    Dec 14, 2018 at 12:26
  • You should use the assembler provided by Digital Research. Jun 30, 2021 at 17:02

2 Answers 2

18

In 8080 Assembler M is the memory referenced to by HL.

Depending on the assembler used this would be written as

  • ADD M (Original Intel 8080 syntax) or
  • ADD A,M (Later Intel syntax as used for example by CP/M's own ASM (*1))

The Z80 assembler equivalent would be

  • ADD A,(HL) (Zilog notation)

Are you sure the source you're compiling made for the Z80 (and a Z80 assembler) at all?

CP/M is by default written in 8080 Assembly, not Z80 or any other substitute. It would make sense that the source you got is meant to be compiled with ASM, as this was the default assembler for CP/M. It would be unusual if it's formatted for any later (Z80) assembler.

Wiki got some condensed remarks about the changes Zilog made to the 8080 Assembly Syntax, like the usage of full register as you might have expected in this example. DR's ASM was an inbetween product, adhering (mostly) to Intel syntax while supporting the Z80 as well.


*1 - Later assemblers where often able to compile 8080 as well as Z80 but using 8080 notation.

1
  • In case this is actually Z80 syntax as OP claimed, an alternative interpretation would be that there's a constant M defined in the source code somehwere and you need to add the constant to the accumulator. So, opcode 0xCE. Dec 19, 2018 at 10:26
4

Depending on the compiler you use, you may need to explicitly state using preprocessor directives that you use 8080 commands. M80 uses .z80 and .8080 to instruct using respective instruction set mnemonics. See https://www.classic-computers.org.nz/system-80/software-manuals/manuals-Macro-80-Assembler.pdf page 20 (16 on the document's page).

If it will not compile in 8080 mode (due to Z80 directives in the source), then it means that sources are altered.The easiest way is to replace M with (HL), but I would not be surprised if resulting executable will not work properly at all.

5
  • Why might the executable not run? Z80 will run any 8080 code unchanged. Dec 14, 2018 at 11:16
  • 2
    Because if it is currently having 8080 mnemonic which does not exist in Z80 set, but at the same time having Z80 mnemonics which do not exist in 8080 set assumes that someone incorrectly touched the code, and its integrity may be compromised (= may not work properly). We do not talk about binary code which of course can be run by Z80, but about source code which does not compile properly returning error.
    – Anonymous
    Dec 14, 2018 at 13:20
  • @Anonymous Either all is 8080 assembly and assembled as such, or all is Z80 assembly and the assembler knows that or it simply won't produce an executable at all. But it should never produce a non-working executable.
    – tofro
    Dec 14, 2018 at 18:49
  • @tofro people may produce incorrect sequences of mnemonics which then converted to incorrect sequences of instructions. In other words - program does not perform what it was expected to perform. I do consider mixing 8080 and Z80 mnemonics as incorrect.
    – Anonymous
    Dec 14, 2018 at 19:33
  • The assembler should do the same - and reject the program.
    – tofro
    Dec 14, 2018 at 19:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .