Question about the Wiki sample Init Code

This is an archive of a topic from NESdev BBS, taken in mid-October 2019 before a server upgrade.
View original topic
Question about the Wiki sample Init Code
by on (#30031)
I was just wondering something. I was looking at someone's code who had based their reset routine off the sample code in the wiki:

http://nesdevwiki.org./wiki/index.php/Init_code

If you look on the wiki it sets the stack pointer to FF but then the clear mem routine runs which (I believe) clears it to zero.

In my code, I always set the stack pointer "after" I clear the memory.

Is the wiki wrong, or does it not really matter? I had thought that the person's code I was looking at was getting its stack hsoed (in FCEU's memory viewer), but I'm still pretty new to this so I'm not really sure.
Al

by on (#30032)
The stack pointer is a seperate register... it does not exist in addressable memory. It can only be changed by TXS (or by a stack push/pull). The clearmem routine is clearing the memory associated with the stack (the $01xx page), but not the stack pointer itself.

So in short... it doesn't matter which you do first, since they're both setting two seperate things.

by on (#30033)
Thanks.
Al