<< Previous Message Main Index Next Message >>
<< Previous Message in Thread This Month Next Message in Thread >>
Date   : Sat, 05 Mar 2005 20:59:08 +0000
From   : Tom Seddon <tom@...>
Subject: [Fwd: Re: Assembler bug]

Argh, I replied straight to Mr Weston! ****. Anyway here is my reply for 
general benefit(?)...

A.Weston wrote:
> Here's an interesting bug I read in an old magazine:
> 
> If you define a zero page variable within assembler an listing then the
> assembler will assume this is a two-byte variable on the first pass and
> as a result any subsequent branch instructions will point to the wrong
> place.
> 
> 
> What does it refer to? How do you define a variable in an assembler
> routine? I had a bug recently but I assumed it was the 6502 bug in that
> when I moved the positions of assembled code about (which are called
> from BASIC with various zero-page ˜ &70-&8F IIRC ˜ bytes set) they
> didn't always work. 

Something like:

(obviously you'll need line numbers when typing this in :)

FORI=1TO3STEP2
P%=&900
[OPTI
JMP P
LDA Z
.P
]
Z=&70
N.

for which one receives output a bit like:

pass 1:

900 4C 00 09 JMP P
903 AD 03 09 LDA Z
906          .P

pass 2:

900 4C 06 09 JMP P
903 A5 70    LDA Z
905          .P

For pass 1, when the assembler assembles "LDA Z" it creates the most
general opcode, because it doesn't know how 'big' the address held by Z
is. It also gives a value to the P label.

On pass 2, the JMP is fixed up using the address of P. But the "LDA Z"
has become smaller, because the most concise encoding of the LDA
instruction can be determined. This moves the location of P, but the JMP
referring to it has already been fixed up, and thus incorrect code is
created.

--Tom
<< Previous Message Main Index Next Message >>
<< Previous Message in Thread This Month Next Message in Thread >>