General Purpose Registers and Where to Find Them

Discussion of hardware and software development for Super NES and Super Famicom. See the SNESdev wiki for more information.

Moderator: Moderators

Forum rules
  • For making cartridges of your Super NES games, see Reproduction.
Post Reply
cleverName
Posts: 2
Joined: Mon Dec 26, 2016 7:45 pm

General Purpose Registers and Where to Find Them

Post by cleverName »

Hey guys, I'm somewhat new to SNES assembly language. I've been reading through the articles on superfamicom and most of it is making pretty decent sense, at least as much as it should after a week or so of studying it. Anyway, I'm attempting to write some simple game logic but for whatever reason I seem to be stuck on finding open registers I can use. It seems like everything is being used by something like OAM or DMA.

My question is how am I supposed to find registers I can store any values I need to remember? Do I just pick registers and see if it screws anything up? I saw some of the memory maps on superfamicom but they don't make a whole lot of sense to me.

Sorry to bother you guys with such a simple question haha. Thanks in advance
tepples
Posts: 22708
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: General Purpose Registers and Where to Find Them

Post by tepples »

Memory at $7E0000-$7FFFFF is free for your use. Additionally, $7E0000-$7E1FFF is mirrored into $0000-$1FFF of banks $00 through $3F and $80 through $BF, so that you can use it as direct page and stack.

Have you programmed for any other 65816-based platform, such as the Apple IIGS?
cleverName
Posts: 2
Joined: Mon Dec 26, 2016 7:45 pm

Re: General Purpose Registers and Where to Find Them

Post by cleverName »

Oh gotcha, thanks! Sadly no... This is actually the only project I've ever attempted for any kind of assembly language. I've read that 65816 isn't the best place to start, but I find it interesting so I'm trying my hand at it.
User avatar
dougeff
Posts: 3079
Joined: Fri May 08, 2015 7:17 pm

Re: General Purpose Registers and Where to Find Them

Post by dougeff »

open registers I can use. It seems like everything is being used by something like OAM or DMA.
Just so you are clear...'registers' at $2100-421f are hardware registers and not processor registers.

65816 has 3 ...16-bit registers, called A,X,Y. Only A can do math and bit shifts/ AND/OR. Therefore, I only consider A to be the general purpose register.

X and Y are typically used for indexing an array, or dereferencing a pointer, or counting loops. They can also be used for finding variables pushed onto the stack with stack relative addressing.

Like tepples said, use the direct page as temporary holders of values. (Or perhaps the stack).
nesdoug.com -- blog/tutorial on programming for the NES
qwertymodo
Posts: 775
Joined: Mon Jul 02, 2012 7:46 am

Re: General Purpose Registers and Where to Find Them

Post by qwertymodo »

Yeah, there really aren't any GPR's, at least not like what you'd see on other architectures. You have the accumulator, the two index registers, and that's pretty much it. It's designed with external memory in mind, which is why you'll see so many instructions with several different addressing variants for operands. Typically the reason for using GPR's is for faster operation, and you can achieve that result using direct-page memory as others have mentioned. A lot of games will use bytes $00-0F in the direct page as local scratchpad, much the same as you would typically use GPR's on other architectures like MIPS (the s/t registers there are a godsend...). Check the superfamicom wiki opcode page, they list the cycle count for all of the opcodes, which should help you figure out how to set up your code to use the faster addressing modes.
User avatar
Memblers
Site Admin
Posts: 4044
Joined: Mon Sep 20, 2004 6:04 am
Location: Indianapolis
Contact:

Re: General Purpose Registers and Where to Find Them

Post by Memblers »

If it helps too, you can find tons of docs, tutorials, simulators, and books for 6502 because that CPU was everywhere. The 65816 is 100% backwards-compatible with the 6502. So that could be a useful way to start out with the basics.
93143
Posts: 1717
Joined: Fri Jul 04, 2014 9:31 pm

Re: General Purpose Registers and Where to Find Them

Post by 93143 »

There are a few differences between the 65816 in emulation mode and the 6502. This includes a couple of bugfixes, but the main difference is that the 6502's unimplemented opcodes (which did unintended but occasionally useful stuff) are now in use as 65816 opcodes and thus do totally different things.

It is claimed that
Eyes and Lichty (1986) wrote:All existing 6502 software can be run by the new processor
but this seems to be weighted with the implication that a 6502 program using illegal opcodes isn't really a 6502 program...
User avatar
koitsu
Posts: 4201
Joined: Sun Sep 19, 2004 9:28 pm
Location: A world gone mad

Re: General Purpose Registers and Where to Find Them

Post by koitsu »

65816 emulation mode operates more like 65c02 than 6502. OP: do not get hung up on this part of the thread conversation.
Post Reply