Nintendo DMG-01 Manual - Page 63
Program Counter, Stack Pointer
View all Nintendo DMG-01 manuals
Add to My Manuals
Save this manual to your list of manuals |
Page 63 highlights
Game BoyTM CPU Manual 3.2.3. Program Counter 3.2.3. Program Counter On power up, the GameBoy Program Counter is initialized to $100 (100 hex) and the instruction found at this location in ROM is executed. The Program Counter from this point on is controlled, indirectly, by the program instructions themselves that were generated by the programmer of the ROM cart. 3.2.4. Stack Pointer A big key to understanding programming in assembly language on the GameBoy is understanding the concept of a stack pointer. A familiarity with assembly language for other processors helps greatly as the concepts are the same. The GameBoy Stack Pointer is used to keep track of the top of the "stack". The stack is used for saving variables, saving return addresses, passing arguments to subroutines, and various other uses that might be conceived by the individual programmer. The instructions CALL, PUSH, and RST all put information onto the stack. The instructions POP, RET, and RETI all take information off of the stack. (Interrupts put a return address on the stack and remove it at their completion as well.) As information is put onto the stack, the stack grows downward in RAM memory. As a result, the Stack Pointer should always be initialized at the highest location of RAM space that has been allocated for use by the stack. For instance, if a programmer wishes to locate the Stack Pointer at the top of low RAM space ($C000-$DFFF) he would set the Stack Pointer to $E000 using the by DP Page 63