user registers?

Building your first 6502-based project? We'll help you get started here.
Post Reply
jeffythedragonslayer
Posts: 114
Joined: 03 Oct 2021

user registers?

Post by jeffythedragonslayer »

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?
User avatar
GARTHWILSON
Forum Moderator
Posts: 8773
Joined: 30 Aug 2002
Location: Southern California
Contact:

Re: user registers?

Post by GARTHWILSON »

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?
User avatar
BigDumbDinosaur
Posts: 9425
Joined: 28 May 2009
Location: Midwestern USA (JB Pritzker’s dystopia)
Contact:

User registers?

Post by BigDumbDinosaur »

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!
User avatar
Dr Jefyll
Posts: 3525
Joined: 11 Dec 2009
Location: Ontario, Canada
Contact:

Re: User registers?

Post by Dr Jefyll »

BigDumbDinosaur wrote:
Of the control registers, PB and PC are the only ones that cannot be readily modified.
BDD, PC and PB are actually pretty easy to modify using BRA, Bxx, JMP, JML, JSR and JSL. :wink:
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
User avatar
barrym95838
Posts: 2056
Joined: 30 Jun 2013
Location: Sacramento, CA, USA

Re: user registers?

Post by barrym95838 »

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. 8)
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
BigDumbDinosaur
Posts: 9425
Joined: 28 May 2009
Location: Midwestern USA (JB Pritzker’s dystopia)
Contact:

Re: User registers?

Post by BigDumbDinosaur »

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!

:P :P :P :wink:

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!
User avatar
BigDumbDinosaur
Posts: 9425
Joined: 28 May 2009
Location: Midwestern USA (JB Pritzker’s dystopia)
Contact:

Re: user registers?

Post by BigDumbDinosaur »

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. 8)

Please see my reply to Jeff.
x86?  We ain't got no x86.  We don't NEED no stinking x86!
soci
Posts: 20
Joined: 18 Nov 2019

Re: User registers?

Post by soci »

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.
It's a matter of interpretation:

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
Plenty of ways to push, pull, load PC/PB and even a bit of arithmetic with PC.
jeffythedragonslayer
Posts: 114
Joined: 03 Oct 2021

Re: user registers?

Post by jeffythedragonslayer »

Ok, so as far as programming goes, I can pretty much ignore any non-user registers. Thanks.
User avatar
BigDumbDinosaur
Posts: 9425
Joined: 28 May 2009
Location: Midwestern USA (JB Pritzker’s dystopia)
Contact:

Re: user registers?

Post by BigDumbDinosaur »

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. :D During the execution of a program, every register that is exposed, even if it cannot be readily modified, will matter as your program worms its way from start to completion.
x86?  We ain't got no x86.  We don't NEED no stinking x86!
jeffythedragonslayer
Posts: 114
Joined: 03 Oct 2021

Re: user registers?

Post by jeffythedragonslayer »

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.
User avatar
GARTHWILSON
Forum Moderator
Posts: 8773
Joined: 30 Aug 2002
Location: Southern California
Contact:

Re: user registers?

Post by GARTHWILSON »

jeffythedragonslayer wrote:
Well, I figure you all don't think about all the internal registers when writing 65x code; that's what I mean.
Right. It's really only the ones who are making 65xx processors in programmable logic (or even discrete logic) who concern themselves with those registers. If you just use the processor as a black box whose data sheet only defines the external behavior, you can be quite expert at programming without knowing anything about various internal registers that are not accessible to the programmer.
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?
Post Reply