[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: 6502 flag behaviour



In article <334D7DEE.1141@erols.com>, Sasha Cimermanis  <scim@erols.com> wrote:
>lda $FE
>ora #$08
>bne <somewhere I don't want it to bne>

>From all the sources on 6502 it appears that the Z flag will always
>be reset at the time of BNE, as we do ORA with a non-zero
>number. But then, this fragment of code loses any sense. Does anyone
>know how Z flag behaves in such situation?

   Yes, the Z flag is set to 0 (false) on the ORA #8. Thus, if the
code enters from the top, the branch will always be taken.

   This suggests several possibilities to me: (1) The 6502 (not
65C02 or 65816) has no 'BRanch Always' (BRA) instruction. If you make
sure that Z is not set, the BNE will always branch. [I'd probably have
used the shorter SEC/BCS or CLC/BCC to do the same thing in this case.]

   (2) Code flow may not necessarily always flow in from the top;
there may be branches/jumps/etc to the second or third instruction,
which could make the branch not necessarily guaranteed.

   (3) The bits in the accumulator are importent in the larger context
of the program, and what you haven't typed in above is significant in
determining program flow.

   (4) The programmer's not clued in about assembly.

   (5) None/all of the above.

Nathan Mates


--
<*> Nathan Mates http://www.visi.com/~nathan/      <*>
# What are the facts? Again and again and again-- what are the _facts_?
# Shun wishful thinking, avoid opinion, care not what the neighbors
# think-- what are the facts, and to how many decimal places?  -R.A. Heinlein