gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

ASM > Quick Stack Question

#1618 - Epo - Mon Jan 20, 2003 7:48 pm

Whats the best way to use the stack?

What I used so far is:

Code:

; To PUSH
str <register>, [r13]+4!

; To POP
sub r13,r13,#0x4
ldr <register>,[r13]


Also, should I check for a stack overflow or something?

#1623 - Touchstone - Mon Jan 20, 2003 8:24 pm

Code:
stmfd   sp!, {r3-r10}      @ push
ldmfd   sp!, {r3-r10}      @ pop

_________________
You can't beat our meat

#1625 - Touchstone - Mon Jan 20, 2003 8:28 pm

Oh, to check your stack usage you can fill your designated stack area with easy to recognize data (like 'STCK' or whatever) and in your gameloop check to make sure that the last slot in the stack is still 'STCK'. You won't see as soon as the stack has been overflowed but you will know within one frame that the stack has been overflowed. If you notice that you have some kind of stack overflow you can start a timer interrupt that check the stack every so often and hope that you'll trap the stack overflow sooner this way. By having designated 'STCK' you can also check total stack usage after the game has been running for a while, that way you'll end up not wasting lots of CPU RAM on unused stack.
_________________
You can't beat our meat

#1630 - Epo - Mon Jan 20, 2003 9:01 pm

Great, thanks!

- Epo