6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Sun Nov 24, 2024 7:39 am

All times are UTC




Post new topic Reply to topic  [ 8 posts ] 
Author Message
PostPosted: Fri Jan 28, 2022 10:04 am 
Offline

Joined: Wed Mar 02, 2016 12:00 pm
Posts: 343
Hi

I was wondering about the stack pointer instructions and flags since the turtorial here doesn't mention it.

Well, PHA for obvious reasons will have the Z or N register set before pushing zero (or a negative number), but what about PLA?

According to the visual6502, PLA will set both Z and N registers if pulling zero or negative number from the stack.

Just so you know... even if it may have been obvious. :P


Top
 Profile  
Reply with quote  
PostPosted: Fri Jan 28, 2022 10:12 am 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8546
Location: Southern California
Yes; pulling anything off the stack, or even reading it without pulling it, will affect the flags.

Let me strongly recommend getting the Lichty & Eyes programming manual, "Programming the 65816—Including the 6502, 65C02 and 65802." This is definitely the best 65xx programming manual available, and a must-have for every 65xx programmer! It starts with the basics, followed by architecture, the CMOS 65c02's many improvements over the original NMOS 6502 including added instructions and addressing modes and fixing the NMOS's bugs and quirks, and then the natural progression to the 65816; a thorough tutorial, writing applications, then very detailed and diagrammed information on all 34 addressing modes, at least a page of very detailed description for each instruction (including effects on flags, since you asked about that), with info on every addressing mode available for that instruction, then instruction lists, tables, and groups, of all 255 active op codes, plus more. 469 pages. From Western Design Center. (.pdf) Note: There were many problems with the earlier .pdf version that were not in the original paper manual; but in late March 2015, WDC scanned and OCR'ed the paper manual and posted the new, repaired .pdf.

_________________
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?


Top
 Profile  
Reply with quote  
PostPosted: Fri Jan 28, 2022 11:03 am 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10986
Location: England
Worth noting that PHA will not affect or use any flags. Even if a zero is the value being pushed, that doesn't mean the flags will reflect that: if the previous operation was, say LDX #FF then the flags will reflect the LDX. Same goes for most instructions which perform an operation which affects or updates the accumulator or a register.

Unlike some other processors, the 6502 doesn't update flags when writing a value to memory. (Unless, of course, it's a read-modify-write operation which performs an operation before the write.)


Top
 Profile  
Reply with quote  
PostPosted: Fri Jan 28, 2022 2:28 pm 
Offline
User avatar

Joined: Thu May 28, 2009 9:46 pm
Posts: 8514
Location: Midwestern USA
GARTHWILSON wrote:
Let me strongly recommend getting the Lichty & Eyes programming manual, "Programming the 65816—Including the 6502, 65C02 and 65802."

Seconded! That manual covers instruction behavior down to the finest detail. There is no excuse for not having a copy at hand.

Time and again, I see the same questions over and over about things that have been documented from here to the dark side of the moon, and back. As I noted in my 65C816 interrupts technical article, “An enormous amount of information about the 6502 family can be found both in printed form and on-line, as it is arguably the most documented microprocessor family ever developed.” Reading available references before posting questions like this goes a long way in helping you understand—and keeps gruff, old curmudgeons from getting on your case for not making an effort to seek the information you wanted.

Speaking of available references, Garth didn't mention his extensive series on stacks. That too may be useful to you.

_________________
x86?  We ain't got no x86.  We don't NEED no stinking x86!


Top
 Profile  
Reply with quote  
PostPosted: Fri Jan 28, 2022 2:41 pm 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10986
Location: England
Fortunately we’re not all curmudgeons here.

Ask away. But do also check the various reference materials on this very site. You can usually find the answer without needing to read a whole book.


Top
 Profile  
Reply with quote  
PostPosted: Sat Jan 29, 2022 4:34 pm 
Offline
User avatar

Joined: Mon Apr 23, 2012 12:28 am
Posts: 760
Location: Huntsville, AL
BigEd wrote:
You can usually find the answer without needing to read a whole book.
Whether the flags are affected on register loads and stores, from memory, other registers, or the stack, is often a characteristic of a processor family that is uniformly implemented. Checking whether flags are affected during register loads and stores is unlikely to require checking the definitions of more than a few instructions.

_________________
Michael A.


Top
 Profile  
Reply with quote  
PostPosted: Sat Jan 29, 2022 4:59 pm 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10986
Location: England
Indeed, a big reference book will (hopefully) contain the information wanted.

However, re-reading the head post I think we might all have misunderstood - I wonder now if the point is that the small section in the linked tutorial, hosted on this site, which lists the stack instructions, has nothing to say about which flags might be affected by each. The other sections on other opcodes are annotated with the affected flags, or 'none'.

I have a feeling we already have a pending update to that particular document.


Top
 Profile  
Reply with quote  
PostPosted: Sat Jan 29, 2022 6:00 pm 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8546
Location: Southern California
Indeed I should not have made it sound like you have to read the whole Lichty & Eyes manual to get the needed information. Yes there's a large tutorial section; but it has several reference sections in the second half, of one which dedicates an entire, very easy-to-read page (sometimes more) to every single instruction, telling exactly what it does, which flags it examines (if any), which flags it affects, all the addressing modes available in that instruction for 6502, 65c02, and 65816, how many cycles, etc.. I occasionally still look things up in the first half; but I'm mostly looking at the reference sections.

_________________
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 63 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: