dont let this stack problem happen to you

Go To Last Post
3 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello:
I made an interesting mistake that cost me several hours...I hope to save others some pain. I am using several math routines & thus need to use up most of the registers. which are already in use by my program. In order to temporarily allow their use I merely push the contents into the stack & perform my massive calculations & then pop them back to restore them. Since I was pushing & popping R15-R22 & thought I might do this several places, I decided for efficiency to make both a push & pop subroutine that could do the work.
I was careful to keep my sequence mirrored so as to avoid trouble:
pushem: push r15, push r16, push r17...etc ret
popem: pop etc, pop r17, pop r16, pop r15, ret

rcall pushem
do massive calculations
rcall popem

looks simple & efficient, right? Well wrong!! My calc went awry & nothing worked well. Of course I spent a good bit messing with the calcs, but my problem was the simple pushing & popping!! Now I realize that you can't push push push then ret, since the return address is buried at the bottom of the stack!! Nor can you go to a routine & just start popping!
So much for efficiency!
:?

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Why don't you write in C?
Then you wouldn't have to worry about that kind of stuff and lose several hours.....

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

or how about change pushem to something like
pop return address
push return address
push registers
push return address
return

and popem could stay the same