2

Title says it all really. Some documentation claims that the S and Z flags are affected by both TXS and TSX, just as with all other transfer commands. Other documentation suggests that neither TXS nor TSX affect the flags.

But this emulator, fake6502 affects the flags with TSX and not with TXS. As fake6502 was made for a NES emulator, could this change be specific to the Ricoh variants? If it's just a bug, then it is worth noting that there is At least one other emulator that behaves this way. I found the source code of perfect6502 too obtuse to read and understand.

I can see how this could be missed in the emulators because I imagine very little code will depend on this. Probably just code that initialises various registers and will overwrite the status flags anyway. Also, I can see how this mistake could be missed in the documentation, the Transfer instructions are all very similar.

I'd be interested if there's any variation in this matter between the various incarnations of the 6502 also.

8
  • 3
    Rather than relying on secondary sources, wouldn't the easiest thing to do be to check the 6502 manual? Wouldn't answer your questions about the Ricoh 2A03 (which does't seem to have a public manual, at least that I could find), but it's a better source for 6502 specs than random third party docs found online.
    – tobiasvl
    Commented Jul 21, 2020 at 21:21
  • Including the 65816 on the fun: "TCS, along with TXS, are the only two instructions for changing the value in the stack pointer. The two are also the only two transfer instructions not to alter the flags." Commented Jul 22, 2020 at 1:43
  • 1
    @KelvinSherlock I don't know where that quote is from but the original 65816 data sheet — e.g. datasheets.chipdb.org/Western%20Design/w65c816s.pdf — shows exactly the same behaviour as Raffzahn's answer, i.e. TSX affects N and Z (bottom of page 39) and TXS does not affect flags (top of page 40).
    – Tommy
    Commented Jul 22, 2020 at 2:57
  • 1
    @Tommy It sounds like the data sheet and Kevin's quote are agreeing.
    – tobiasvl
    Commented Jul 22, 2020 at 7:37
  • 1
    @tobiasvl yes, but more explicitly. Also, to the originating poster: I think your 'other documentation suggests' is the best way to look at it; I notice they've omitted the 'Affects flags:' text from the relevant section so, technically, no opinion is stated.
    – Tommy
    Commented Jul 22, 2020 at 14:26

1 Answer 1

9

Does the 6502's TXS and TSX affect flags or not?

  • TSX does affect N and Z
  • TXS does not affect any flag

In general all instructions moving data to one of the Registers (A, X, Y) do set N and Z according to the data moved.

Excerpt of the instruction list from the 1976 data sheet on page 6:

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .