On Wed, May 09, 2007 at 12:23:30PM +0100, David Brant wrote: > Also I have found a mistake in Comet. You all may know about this one and > normally would not come up. > > if you type: > > DUMP address > ORG address > > JP start > > ;some code > > start: > ;some more code > > address: EQU 40000 ; or any address except 32768 > > Comet will NOT come up with an error but JP start will jump to the wrong > address but dump it to the right one. > I only found this out because I'm writing my own assembler so I've been > seeing how comet works.
Hi, Interesting problem. pyz80 can't handle it either, but at least it has the grace to issue an error message. The reason this doesn't work - at least in pyz80, and I assume Comet is similar - is that the assembler reads the file top-to-bottom exactly twice, and assumes that all addresses can be known precisely, at the time they are used in the second pass. Effectively, this means that the ORG address must be known the first time you reach it in pass 1 (actually, pyz80 is coded to require the DUMP address in pass 1 as well, but this probably isn't strictly necessary). So in this example, in the first pass we see "ORG address" but we don't know address, so we don't know $. When we get to start:, we still don't $, so we can't decide what "start" should be either. Then we get to address: which is defined explicitly, so we can pick up this value. In the second pass, we see ORG address and we now do know this. But when we get to JP start, we don't know the value yet. It may be possible to parse this file by running more than two assembler passes, but I don't think people write like this very often... Andrew -- --- Andrew Collier ---- ---- http://www.intensity.org.uk/ --- -- r<2+ T<4* cSEL dMS hEn/CB<BL A4 S+*<++ C$++L/mP W- a-- Vh+seT+ (Cantab) 1.1.4