[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: 6502 flag behaviour
Sasha Cimermanis <scim@erols.com> wrote:
>
>Hi everyone,
>
>
>I'm trying to help someone out regarding 6502 flag behaviour. Here is
>the problem.
>
>I have recently encountered a following piece of code:
>
>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?
The Z flag will be set only if the last operation (bit, add, subtract, cmp,
etc)
yielded a 0 result, so the branch above will always be taken.
This is actually pretty common in 6502 assembly--I did it all the time. If you
need to jump to somewhere within +/- 127 bytes, look above and find some
condition that is always true, and branch on it. Compared to a regular JMP,
saves 1 byte and several machine cycles.
David S.