Need clarity on return address and function arguments

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Need clarity on return address and function arguments

harshchikorde1234@gmail.com
When I am calling a function
1) all the arguments are pushed into the stack
2)Return address is pushed

my question is when I am calling a function with the command 'call |function name| no of args' here in this command we are only specifying the number of arguments passed by the calling function to the called function, but not the actual argument values! so when textbook means pushing arguments what do they mean? passing actual arguments or just assigning memory space or the VM code is written such that the arguments required by the called function should be consciously pushed before calling the function(what I mean is all the VM commands before calling the function have already pushed the arguments into the stack and I need not worry about it)?

secondly whenever we push a return address that means a label is created in the assembly code at the line number just before the function is being called and this label is pushed into the stack for the 'return' command to recognize right?

Also, I am a bit confused about the booting concept can you please explain it in short!

Reply | Threaded
Open this post in threaded view
|

Re: Need clarity on return address and function arguments

WBahn
Administrator
When you write a VM program, it is not that far removed from writing an ASM program. It is the responsibility of the person writing the program to push the arguments onto the stack BEFORE they call the function. The 'call' command has to include the number of arguments because the VM has to know how many arguments were pushed onto the stack so that it can take that into account when determining where the beginning of the ARG segment is.

Similarly, the 'function' command has to include the number of local variables so that the VM can allocated memory for them on the stack and initialize them to zero.

Yes, your VM translator will need to add a unique label to the generated ASM code and push this label onto the stack.

The booting process is fairly simple. When the computer is reset is starts execution at ROM[0] and with nothing but unknown junk in RAM. Before your program can run successfully, a few RAM locations need to be set up properly. For instance, the Stack Pointer needs to be set so that the it points to the first memory location on the stack. Once the initialization of RAM is done, it then needs to call a specific function to get the VM program running.