user registers?
-
jeffythedragonslayer
- Posts: 114
- Joined: 03 Oct 2021
user registers?
Hi, I am going through the 2015 edition of "Programming the 65816" by Ron Lichty & David Eyes and the book mentions "user registers." This term does not appear in the index. Which of the 6502 (and related processors) registers are user registers, and is there any other kind of register?
- GARTHWILSON
- Forum Moderator
- Posts: 8773
- Joined: 30 Aug 2002
- Location: Southern California
- Contact:
Re: user registers?
That would be the registers that are accessible to the user, as opposed to the instruction register, the input data latch, adder hold register, data output register, ADH, ADL, and other internal ones the user cannot access directly.
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?
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?
- BigDumbDinosaur
- Posts: 9425
- Joined: 28 May 2009
- Location: Midwestern USA (JB Pritzker’s dystopia)
- Contact:
User registers?
jeffythedragonslayer wrote:
Hi, I am going through the 2015 edition of "Programming the 65816" by Ron Lichty & David Eyes and the book mentions "user registers." This term does not appear in the index. Which of the 6502 (and related processors) registers are user registers, and is there any other kind of register?
Expanding on what Garth said, the "user registers" are those that are accessible through machine instructions in your program. Within that group, registers may be classified as "general purpose" (GP) or "control."
A GP register would ordinarily be used to perform data fetches and stores, computations, comparisons and counting. A control register would be used to affect operating conditions, e.g., program flow, in some way. In most programs, instructions that use the GP registers make up the bulk of the code.
There are a wide variety of instructions and addressing modes that may be used with the 6502-family GP registers. In contrast, instructions that are able to directly access control registers are quite limited, often requiring a sequence of instructions to gain access. In many cases, programs don't normally change the values in control registers via fetches and stores.
In the 65(c)02, the general-purpose registers are .A (accumulator), .X (index) and .Y (index)—all three are 8-bit registers. The control registers are PC (16-bit program counter), SP (8-bit stack pointer, sometimes referred to as S) and SR (8-bit status register, sometimes referred to as P). Of the three control registers, only SP and SR can be readily modified.
In the 65C816, the general-purpose registers are .A (8-bit primary accumulator), .B (8-bit secondary accumulator), .C (16-bit accumulator, which is .A and .B "ganged" together), .X (8- or 16-bit index) and .Y (8- or 16-bit index). The 65C816 control registers are DB (8-bit data bank), DP (16-bit direct page pointer, direct page being the 65C816 equivalent of the 65C02's zero page), PB (8-bit program bank), PC (16-bit program counter), SP (16-bit stack pointer) and SR (9-bit status register). Of the control registers, PB and PC are the only ones that cannot be readily modified.
x86? We ain't got no x86. We don't NEED no stinking x86!
Re: User registers?
BigDumbDinosaur wrote:
Of the control registers, PB and PC are the only ones that cannot be readily modified.
Last edited by Dr Jefyll on Wed Oct 06, 2021 2:13 pm, edited 1 time in total.
In 1988 my 65C02 got six new registers and 44 new full-speed instructions!
https://laughtonelectronics.com/Arcana/ ... mmary.html
https://laughtonelectronics.com/Arcana/ ... mmary.html
- barrym95838
- Posts: 2056
- Joined: 30 Jun 2013
- Location: Sacramento, CA, USA
Re: user registers?
You left out BRK, RTI, RTS, COP and RTL Jeff. Slower but unbeatable for code density, so they float to the top of my list. 
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)
Mike B. (about me) (learning how to github)
- BigDumbDinosaur
- Posts: 9425
- Joined: 28 May 2009
- Location: Midwestern USA (JB Pritzker’s dystopia)
- Contact:
Re: User registers?
Dr Jefyll wrote:
PC and PB are actually pretty easy to modify using BRA, Bxx, JMP, JML, JSR and JSL. Maybe it'd be helpful to familiarize yourself with those instructions, BDD!

Not so.
Neither PB or PC can modified by a copy from another register or by a stack pull instruction. For instance, it's not possible to simply load a general-purpose register with a value and copy it to either of those registers, even through the stack. Another for instance: while it's possible to change the value in DP by loading .C and then executing TCD, or change DB by pulling it from the stack (PLB), no such methods exist for PB and PC. Therefore, they are not readily modified.
x86? We ain't got no x86. We don't NEED no stinking x86!
- BigDumbDinosaur
- Posts: 9425
- Joined: 28 May 2009
- Location: Midwestern USA (JB Pritzker’s dystopia)
- Contact:
Re: user registers?
barrym95838 wrote:
You left out BRK, RTI, RTS, COP and RTL Jeff. Slower but unbeatable for code density, so they float to the top of my list. 
Please see my reply to Jeff.
x86? We ain't got no x86. We don't NEED no stinking x86!
Re: User registers?
BigDumbDinosaur wrote:
Neither PB or PC can modified by a copy from another register or by a stack pull instruction. For instance, it's not possible to simply load a general-purpose register with a value and copy it to either of those registers, even through the stack. Another for instance: while it's possible to change the value in DP by loading .C and then executing TCD, or change DB by pulling it from the stack (PLB), no such methods exist for PB and PC. Therefore, they are not readily modified.
Code: Select all
PER ; push the sum of PC and a 16 bit immediate to stack
JSR ; push PC to stack and load immediate value or indexed indirect
JSL ; push PC and PB to stack and load immediate value
RTS ; pull PC from stack
RTI ; pull PC, PB and SR from stack
RTL ; pull PC and PB from stack
JMP ; load immediate value or indirect or indexed indirect to PC
JML ; load immediate to PC and PB
BRx ; add sign extended 8 bit immediate value to PC
BRL ; add 16 bit intermediate value to PC
BRK ; push PC, PB and SR to stack and load PC from memory and clear PB
COP ; push PC, PB and SR to stack and load PC from memory and clear PB
-
jeffythedragonslayer
- Posts: 114
- Joined: 03 Oct 2021
Re: user registers?
Ok, so as far as programming goes, I can pretty much ignore any non-user registers. Thanks.
- BigDumbDinosaur
- Posts: 9425
- Joined: 28 May 2009
- Location: Midwestern USA (JB Pritzker’s dystopia)
- Contact:
Re: user registers?
jeffythedragonslayer wrote:
Ok, so as far as programming goes, I can pretty much ignore any non-user registers. Thanks.
Not exactly. To paraphrase an often-heard slogan, all registers matter.
x86? We ain't got no x86. We don't NEED no stinking x86!
-
jeffythedragonslayer
- Posts: 114
- Joined: 03 Oct 2021
Re: user registers?
Well, I figure you all don't think about all the internal registers when writing 65x code; that's what I mean. I'm curious which ones I can consider magic.
- GARTHWILSON
- Forum Moderator
- Posts: 8773
- Joined: 30 Aug 2002
- Location: Southern California
- Contact:
Re: user registers?
jeffythedragonslayer wrote:
Well, I figure you all don't think about all the internal registers when writing 65x code; that's what I mean.
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?
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?