6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Mon Apr 29, 2024 3:16 pm

All times are UTC




Post new topic Reply to topic  [ 12 posts ] 
Author Message
 Post subject: user registers?
PostPosted: Sun Oct 03, 2021 2:47 am 
Offline

Joined: Sun Oct 03, 2021 2:17 am
Posts: 114
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?


Top
 Profile  
Reply with quote  
 Post subject: Re: user registers?
PostPosted: Sun Oct 03, 2021 5:20 am 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8428
Location: Southern California
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?


Top
 Profile  
Reply with quote  
 Post subject: User registers?
PostPosted: Sun Oct 03, 2021 9:18 am 
Offline
User avatar

Joined: Thu May 28, 2009 9:46 pm
Posts: 8155
Location: Midwestern USA
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!


Top
 Profile  
Reply with quote  
 Post subject: Re: User registers?
PostPosted: Sun Oct 03, 2021 3:08 pm 
Offline
User avatar

Joined: Fri Dec 11, 2009 3:50 pm
Posts: 3349
Location: Ontario, Canada
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:

_________________
In 1988 my 65C02 got six new registers and 44 new full-speed instructions!
https://laughtonelectronics.com/Arcana/ ... mmary.html


Last edited by Dr Jefyll on Wed Oct 06, 2021 2:13 pm, edited 1 time in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: user registers?
PostPosted: Sun Oct 03, 2021 4:43 pm 
Offline
User avatar

Joined: Sun Jun 30, 2013 10:26 pm
Posts: 1927
Location: Sacramento, CA, USA
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)


Top
 Profile  
Reply with quote  
 Post subject: Re: User registers?
PostPosted: Sun Oct 03, 2021 7:48 pm 
Offline
User avatar

Joined: Thu May 28, 2009 9:46 pm
Posts: 8155
Location: Midwestern USA
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!


Top
 Profile  
Reply with quote  
 Post subject: Re: user registers?
PostPosted: Sun Oct 03, 2021 7:49 pm 
Offline
User avatar

Joined: Thu May 28, 2009 9:46 pm
Posts: 8155
Location: Midwestern USA
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!


Top
 Profile  
Reply with quote  
 Post subject: Re: User registers?
PostPosted: Tue Oct 05, 2021 6:17 pm 
Offline

Joined: Mon Nov 18, 2019 8:08 pm
Posts: 9
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:
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.


Top
 Profile  
Reply with quote  
 Post subject: Re: user registers?
PostPosted: Mon Oct 25, 2021 2:49 am 
Offline

Joined: Sun Oct 03, 2021 2:17 am
Posts: 114
Ok, so as far as programming goes, I can pretty much ignore any non-user registers. Thanks.


Top
 Profile  
Reply with quote  
 Post subject: Re: user registers?
PostPosted: Mon Oct 25, 2021 4:10 am 
Offline
User avatar

Joined: Thu May 28, 2009 9:46 pm
Posts: 8155
Location: Midwestern USA
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!


Top
 Profile  
Reply with quote  
 Post subject: Re: user registers?
PostPosted: Mon Oct 25, 2021 5:54 am 
Offline

Joined: Sun Oct 03, 2021 2:17 am
Posts: 114
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.


Top
 Profile  
Reply with quote  
 Post subject: Re: user registers?
PostPosted: Mon Oct 25, 2021 6:48 am 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8428
Location: Southern California
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?


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

All times are UTC


Who is online

Users browsing this forum: No registered users and 16 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: