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

Re: 6502 flag behaviour



David Schmidt <anonymous@fight.spam> wrote:

<quote>
>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.
</quote>

Actually, David, it just saves a byte--it may actually _cost_ a cycle if
it
crosses a page boundary.  A JMP always costs 3 cycles, as does a
non-page-crossing conditional branch.  A page-crossing conditional
branch costs 4 cycles.

-michael

 Email:  mjmahon@aol.com
 Home page:  http://members.aol.com/MJMahon/