I feel like I'm starting to get the hang of z80 asm after a few months, but I really feel like I've been under-utilizing stacks. For me, trying to use a stack effectively is like trying to fall down a flight of stairs gracefully... it just can't happen.

So, that being said, does anybody know of any articles that discuss working efficiently and gracefully with stacks, or could you maybe post your own tips about working with stacks here?

Moved to asm board. Mods don't need your permission.
How are you using the stack now? That might give us a good idea of where you should look next. You're pluralizing it, are you using multiple stacks?
I pluralized "stack" because I meant stacks in general, but yes, I am only using one stack.
And I'm using it to store data from previous calculations that I want to retrieve later and don't have room for in the registers.
Hmm, I'd suggest just looking up some algorithms that use stacks so you can get a good feel for how they work. A Towers of Hanoi solver or RPN calculator or something would be a good step. Also, DCS adds stacks to BASIC, so it might be easier to play around in that while you're just playing with stacks.
merthsoft wrote:
Hmm, I'd suggest just looking up some algorithms that use stacks so you can get a good feel for how they work. A Towers of Hanoi solver or RPN calculator or something would be a good step. Also, DCS adds stacks to BASIC, so it might be easier to play around in that while you're just playing with stacks.


Thank you so much for these great ideas!! I really like the tower of Hanoi one. It will help a ton. Thank you so much.
Also, I'd like to throw my two cents in...

It's bad programming practice to use the stack (or anything, for that matter) just because you can or because you FEEL like you are underusing it. You should be programming for speed and/or size, so if using the stack advances those goals, then do it, but if not, don't use it. Wink
While I agree that you shouldn't use something unless you really need to, learning to use the stack effectively is a very important thing. Even if what he does is abuse the stack in one program, for the purpose of learning, that doesn't necessarily mean that it's a bad thing. Not to mention, writing code that uses and abuses stacks is fun, especially when it is all the language has (JVM ASM/Java Bytecode, and FORTH spring to mind Smile)
One thing you could do to "save" information if you simply need it later is to store the information further into the program where it IS used again:

Code:
 ld (temp+1),a
 ...
temp:
 ld a,0
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement