Program Counter; Stack Pointer - Nintendo DMG-01 - Game Boy Console Manual

Manual
Table of Contents

Advertisement

TM
Game Boy
CPU Manual

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
3.2.3. Program Counter
Page 63

Hide quick links:

Advertisement

Table of Contents
loading

This manual is also suitable for:

Game boy

Table of Contents