View Single Post
Old 18 December 2015, 20:32   #20
Mrs Beanbag
Glastonbridge Software
 
Mrs Beanbag's Avatar
 
Join Date: Jan 2012
Location: Edinburgh/Scotland
Posts: 2,243
yes, although we are not talking about returning the address of a local variable, but a function not leaving the stack in the same place it found it when it returns*, which means if the caller is doing relative (SP) addressing to access its own local variables, it will go completely out of whack and do nasty things.

Unless you have some specific, strict coding style that handles this sort of thing, i've thought before about what if you want a function to return an object whose size isn't known to the caller and might not be a constant... but i can't think of a neat way to do that anyway without using two stacks.

(*which is impossible for a C function anyway)

Quote:
Originally Posted by Leffmann View Post
One thing that could be good to know if you're playing with the stack like this: Exec uses your own stack when it switches tasks, so if you ever make multi-tasking programs then you can't use A7 as a general purpose register, it must always point to the top of your stack.
now that is good to know, it also means you shouldn't keep any temporary data before the stack pointer, because it could get written over at any point.

Last edited by Mrs Beanbag; 18 December 2015 at 22:21.
Mrs Beanbag is offline  
 
Page generated in 0.05094 seconds with 10 queries