| ▲ | adrian_b 2 days ago | ||||||||||||||||||||||
You have to use the stack for procedure calls on x86/x86-64 CPUs, where the hardware enforces this. In most other surviving CPU ISAs the return address is saved in a register and it is easy to arrange in a compiler to use only procedure arguments that are passed in registers, the only price being paid for this being a reasonable upper limit for the number of parameters of a function, e.g. 12 or 24, depending on the number of general-purpose registers (e.g. 16 or 32). For the very rare case when a programmer would want more parameters, some of them should be grouped into a structure. With this convention, which normally should not be a problem, there is no need for a call stack. There can be software managed stacks, which can be used even for implementing recursion, when that is desired. The use of static memory for passing function arguments was necessary only in the very early computers, which were starved in registers. | |||||||||||||||||||||||
| ▲ | RealityVoid 2 days ago | parent | next [-] | ||||||||||||||||||||||
I believe it's possible to do what you've described, but I am not aware of any compiler that does this. What do you get by doing it like this? Also, in your described structure, how do you handle nested function calls? I'm sure there exists a convoluted scheme that does this, but not sure with the current call assumptions. You also lose ABI compatibility with a bunch of stuff. And regardless, I mostly program in Risc-v and ARM -most compiles like to pass arguments on the registers, but use the stack anyway for local context. | |||||||||||||||||||||||
| |||||||||||||||||||||||
| ▲ | 0xffff2 2 days ago | parent | prev [-] | ||||||||||||||||||||||
I honestly can't tell if you know a lot more than me or a lot less than me about how computers work... A couple of honest questions: 1. Where do you save the current value of the return address register before calling a function? 2. When parameters are "grouped into a structure" and the structure is passed as an argument to a function, where do you store that structure? | |||||||||||||||||||||||
| |||||||||||||||||||||||