Hello!
I'm about to begin programming a CHIP-8 emulator, and I pretty much understand everything I need to know, but I am a bit confused as how to program the stack. I would like to know if the following is correct. I am using C++, so I would create a 16 value array, and an integer for the stack pointer. When my emulator comes across a call to a subroutine, it would store the value of the PC in stack[stackpointer], and increment the stack pointer by one. It will jump to the address that the subroutine is located at, and when it comes across 0x00EE (return from a subroutine), it will store stack[stackpointer] + 1 in the PC, and decrement the stack pointer by one. Is this correct?
I also read that the subroutines are stored at the end of programs. If this is true, how does the emulator know not to execute the code in the subroutine? I have found no opcode to signal the beginning of a subroutine.
Thanks a ton!
~Matt
I'm about to begin programming a CHIP-8 emulator, and I pretty much understand everything I need to know, but I am a bit confused as how to program the stack. I would like to know if the following is correct. I am using C++, so I would create a 16 value array, and an integer for the stack pointer. When my emulator comes across a call to a subroutine, it would store the value of the PC in stack[stackpointer], and increment the stack pointer by one. It will jump to the address that the subroutine is located at, and when it comes across 0x00EE (return from a subroutine), it will store stack[stackpointer] + 1 in the PC, and decrement the stack pointer by one. Is this correct?
I also read that the subroutines are stored at the end of programs. If this is true, how does the emulator know not to execute the code in the subroutine? I have found no opcode to signal the beginning of a subroutine.
Thanks a ton!
~Matt