Page 1 of 1

user registers?

Posted: Sun Oct 03, 2021 2:47 am
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?

Re: user registers?

Posted: Sun Oct 03, 2021 5:20 am
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.

User registers?

Posted: Sun Oct 03, 2021 9:18 am
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.

Re: User registers?

Posted: Sun Oct 03, 2021 3:08 pm
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:

Re: user registers?

Posted: Sun Oct 03, 2021 4:43 pm
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)

Re: User registers?

Posted: Sun Oct 03, 2021 7:48 pm
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.

Re: user registers?

Posted: Sun Oct 03, 2021 7:49 pm
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.

Re: User registers?

Posted: Tue Oct 05, 2021 6:17 pm
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.

Re: user registers?

Posted: Mon Oct 25, 2021 2:49 am
by jeffythedragonslayer
Ok, so as far as programming goes, I can pretty much ignore any non-user registers. Thanks.

Re: user registers?

Posted: Mon Oct 25, 2021 4:10 am
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.

Re: user registers?

Posted: Mon Oct 25, 2021 5:54 am
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.

Re: user registers?

Posted: Mon Oct 25, 2021 6:48 am
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.