Hi there. I was curious whether many here "imitate" function calls using a calling convention in conjuction with the stack?
I had the impression for the longest time that, for variables used in functions, fixed locations would be put aside for temporary variables and these would be used and overwritten as needed; the burden of ensuring things are where they need to be at the right time and preserved when they need to be is on the programmer as each function doesn't really have its own "frame" so to speak.
However, I noticed some time ago (sorry, can't remember where) someone's code on here seemed to be using the sort of calling convention you'd see in, for example, the C language. Function arguments are pushed onto the stack, said function is jumped to, uses the arguments by indexing into the stack, and then "returns" the result by putting it in a fixed location, or leaving it on the stack, or something like that. Each function expects arguments to be at certain offsets from (its) base stack pointer, and each function ensures that everything is "as it was" before it was called when it returns - that is, other than leaving the result in an expected place as mentioned prior.
Just wanted to get an idea of how many of you guys do this sort of thing, and how viable it is? From what I remember, the 6502 doesn't have particularly good stack accessing opcodes, so I figure that might have an impact to some degree.
Thanks
I had the impression for the longest time that, for variables used in functions, fixed locations would be put aside for temporary variables and these would be used and overwritten as needed; the burden of ensuring things are where they need to be at the right time and preserved when they need to be is on the programmer as each function doesn't really have its own "frame" so to speak.
However, I noticed some time ago (sorry, can't remember where) someone's code on here seemed to be using the sort of calling convention you'd see in, for example, the C language. Function arguments are pushed onto the stack, said function is jumped to, uses the arguments by indexing into the stack, and then "returns" the result by putting it in a fixed location, or leaving it on the stack, or something like that. Each function expects arguments to be at certain offsets from (its) base stack pointer, and each function ensures that everything is "as it was" before it was called when it returns - that is, other than leaving the result in an expected place as mentioned prior.
Just wanted to get an idea of how many of you guys do this sort of thing, and how viable it is? From what I remember, the 6502 doesn't have particularly good stack accessing opcodes, so I figure that might have an impact to some degree.
Thanks