How to remember the flags of the 65816's P register

Programming the 6502 microprocessor and its relatives in assembly and other languages.
jeffythedragonslayer
Posts: 114
Joined: 03 Oct 2021

How to remember the flags of the 65816's P register

Post by jeffythedragonslayer »

This is a little silly, but it solved my problem of not being able to read SEP/REP so I'm dropping the tip here. I think nvmxdizc should be pronounced "nevermind x disc."
User avatar
GARTHWILSON
Forum Moderator
Posts: 8773
Joined: 30 Aug 2002
Location: Southern California
Contact:

Re: How to remember the flags of the 65816's P register

Post by GARTHWILSON »

Just put the manipulation in macros so you don't have to remember it, and source code becomes a lot more readable. I called mine ACCUM_16, ACCUM_8, INDEX_16, and INDEX_8. I think BDD called his LONGA, SHORTA, etc..
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?
User avatar
BigDumbDinosaur
Posts: 9425
Joined: 28 May 2009
Location: Midwestern USA (JB Pritzker’s dystopia)
Contact:

Re: How to remember the flags of the 65816's P register

Post by BigDumbDinosaur »

jeffythedragonslayer wrote:
This is a little silly, but it solved my problem of not being able to read SEP/REP so I'm dropping the tip here. I think nvmxdizc should be pronounced "nevermind x disc."

As Garth said, use macros so you don't have to memorize the bit patterns for REP and SEP. My macros are:

  • LONGA — set the accumulator and memory accesses to 16 bits: REP #%00100000
  • LONGR — set all registers to 16 bits: REP #%00110000
  • LONGX — set index registers to 16 bits: REP #%00010000
  • SHORTA — set the accumulator and memory accesses to 8 bits: SEP #%00100000
  • SHORTR — set all registers to 8 bits: SEP #%00110000
  • SHORTX — set index registers to 8 bits: REP #%00010000


Incidentally, the "P" register is SR, which is the designation used in almost all machine language monitors used with the 65xx family. Also, REP and SEP can be used to manipulate any of the bits in SR, not just m and x.
x86?  We ain't got no x86.  We don't NEED no stinking x86!
User avatar
BigEd
Posts: 11463
Joined: 11 Dec 2008
Location: England
Contact:

Re: How to remember the flags of the 65816's P register

Post by BigEd »

Come on BDD, you know full well that this SP notation is just another of your idiosyncrasies. It's just as common, if not more so, to call the P register P, as in the mnemonics PHP, PLP.

You really ought to quit this bad habit of announcing things as facts when they are not. It weakens your reputation.
User avatar
BigDumbDinosaur
Posts: 9425
Joined: 28 May 2009
Location: Midwestern USA (JB Pritzker’s dystopia)
Contact:

Re: How to remember the flags of the 65816's P register

Post by BigDumbDinosaur »

BigEd wrote:
Come on BDD, you know full well that this SP notation is just another of your idiosyncrasies. It's just as common, if not more so, to call the P register P, as in the mnemonics PHP, PLP.

You really ought to quit this bad habit of announcing things as facts when they are not. It weakens your reputation.

Almost all extant 6502 machine code monitors refer to the status register as SR in the register dump display—also, the stack pointer is referred to as SP. Take a look at the first attachment, which is the January/February 1980 issue of Transactor magazine. In it is an article about Supermon for the Commodore PET. On page 17, the .R (register display) command is described, complete with an example of what a register dump looks like. You’ll have to rotate the page view clockwise.

The second attachment is an excerpt from the January 1983 issue of Compute, in which there was an article about Supermon 64. If you scroll down, you will see how the register dump appears.

Supermon had a number of contributors to its design, Steve Wozniak indirectly being one of them. Jim Butterfield was the one who took the bits and pieces and created the actual Supermon package that was used by innumerable Commodore M/L programmers. He then ported it to the C-64. Commodore, in turn, ported it to the C-128. I got a lot of use from the C-128’s monitor (and the C-128's reset button) when I wrote the truck leasing and billing system. :D

Incidentally, I wrote a number of articles that were published in Transactor.

transactor_v2_i08.pdf
Transactor Magazine
(1.94 MiB) Downloaded 138 times
supermon64.pdf
Compute Excerpt w/Supermon 64
(437.53 KiB) Downloaded 140 times

——————————
Edit: Fixed a typo.
Last edited by BigDumbDinosaur on Wed Jun 01, 2022 7:25 pm, edited 1 time in total.
x86?  We ain't got no x86.  We don't NEED no stinking x86!
User avatar
BigEd
Posts: 11463
Joined: 11 Dec 2008
Location: England
Contact:

Re: How to remember the flags of the 65816's P register

Post by BigEd »

Indeed, Supermon is an example of one particular notation. And the mnemonics we all use constitute another example. Including the REP and SEP which motivate this thread. (Oh, also the datasheet, and Zaks, and Leventhal...)
User avatar
Windfall
Posts: 229
Joined: 27 Nov 2011
Location: Amsterdam, Netherlands
Contact:

Re: How to remember the flags of the 65816's P register

Post by Windfall »

The nice thing about conventions is that there are so many to choose from (paraphrasing Tanenbaum).
User avatar
barrym95838
Posts: 2056
Joined: 30 Jun 2013
Location: Sacramento, CA, USA

Re: How to remember the flags of the 65816's P register

Post by barrym95838 »

Capture.PNG
Capture.PNG (4.36 KiB) Viewed 2297 times
Quod erat demonstrandum.
Got a kilobyte lying fallow in your 65xx's memory map? Sprinkle some VTL02C on it and see how it grows on you!

Mike B. (about me) (learning how to github)
User avatar
GARTHWILSON
Forum Moderator
Posts: 8773
Joined: 30 Aug 2002
Location: Southern California
Contact:

Re: How to remember the flags of the 65816's P register

Post by GARTHWILSON »

Quote:
And the mnemonics we all use constitute another example. Including the REP and SEP which motivate this thread.
Quote:
The nice thing about conventions is that there are so many to choose from (paraphrasing Tanenbaum).
It would be nice if all the terminology were consistent; but alas, we even have BBR (branch on bit reset), RMB (reset memory bit), REP (reset processor status bit), but BCC (branch on carry clear, not branch on carry reset), BVC (branch on overflow clear, not reset), CLD (clear, not reset, decimal flag), etc.. I tend to prefer the one-letter designators so the length is consistent, like A, X, Y, S, and P (without leading dots which make left-justify look messy), but then 816's K and B are extra confusing, and then there's ADH (address high byte), ADL, and probably more I'm forgetting. I/O ICs may add confusion too, like SR being the VIA's shift register. I've never used a monitor program. I wonder if they differ as much from one to another as assemblers do in their directives. Fortunately it doesn't take much work to modify code written for one assembler to work on another. I'm sure I could find better things to get myself worked up about.
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?
jmthompson
Posts: 127
Joined: 30 Dec 2017
Location: Detroit, Michigan, USA
Contact:

Re: How to remember the flags of the 65816's P register

Post by jmthompson »

FWIW, I recently changed the monitor in my JRC-1 board to use single-letter designations for all the registers that the monitor lets you modify before jumping into code, so "A", "X", "Y", "P", "S", "D", and "B". Previously "P" was "SR'", "S" was "SP", and "B" was "DB". I found I liked it better making everything one letter. It makes my command line parsing a bit easier, and as has been mentioned above, these letters match the ones used in the opcodes (except for those few opcodes that use "C" to refer unambiguously to the 16-bit accumulator, of course).

In the end, since we're all more or less the only users of our builds, use whatever you want. :)
jeffythedragonslayer
Posts: 114
Joined: 03 Oct 2021

Re: How to remember the flags of the 65816's P register

Post by jeffythedragonslayer »

For nv1bdizc in emulation mode, "never one blu-ray disc"
User avatar
BigEd
Posts: 11463
Joined: 11 Dec 2008
Location: England
Contact:

Re: How to remember the flags of the 65816's P register

Post by BigEd »

I tend to mash up and try to pronounce strings of consonants - it mightn't make any sense, but it kind of works for me!
User avatar
Windfall
Posts: 229
Joined: 27 Nov 2011
Location: Amsterdam, Netherlands
Contact:

Re: How to remember the flags of the 65816's P register

Post by Windfall »

jeffythedragonslayer wrote:
For nv1bdizc in emulation mode, "never one blu-ray disc"
Imagine that in 1975. So forward looking.
User avatar
Sheep64
In Memoriam
Posts: 311
Joined: 11 Aug 2020
Location: A magnetic field

Re: How to remember the flags of the 65816's P register

Post by Sheep64 »

I prefer F for flags because it is difficult enough to remember the properties of A, B, C and D across multiple processor architectures. However, I use P and 6516's Q because it is compatible with established, three letter opcodes.

Looking at jeffythedragonslayer's mnemonic and BigDumbDinosaur's macros, I wonder if it is useful to clear decimal flag and carry flag when using REP to enter 65816's 16 bit modes.
User avatar
BigDumbDinosaur
Posts: 9425
Joined: 28 May 2009
Location: Midwestern USA (JB Pritzker’s dystopia)
Contact:

Re: How to remember the flags of the 65816's P register

Post by BigDumbDinosaur »

Sheep64 wrote:
Looking at jeffythedragonslayer's mnemonic and BigDumbDinosaur's macros, I wonder if it is useful to clear decimal flag and carry flag when using REP to enter 65816's 16 bit modes.

Before answering, let me point out the 65C816 doesn’t have “16-bit modes.” There’s 65C02 emulation mode (which doesn’t extend to the hardware itself) and 65C816 native mode. In native mode, register “width” may be set to eight or 16 bits.

REP and SEP may be used with any bit combination desired, a feature I often employ in functions. I give each bit a name, e.g., SR_CAR for the carry bit and SR_ZER for the result zero bit, and if setting or clearing multiple bits, I OR them in the operand. For example, REP #SR_ZER | SR_CAR. The only bit that cannot be affected by REP and SEP is the hidden emulation bit E, which must be indirectly toggled via the XCE instruction.

In cases where the only thing being changed are register widths, I use the aforementioned macros (LONGA, SHORTR, etc.) to cut down a bit on typing, as well as minimize the likelihood of an error sneaking into the code.
x86?  We ain't got no x86.  We don't NEED no stinking x86!
Post Reply