What are the ways to transfer data between a subroutine and its calling program?

If we are talking about high-level languages, then the data is transferred: 1) Through global variables. 2) Through the parameters of the subroutine. 3) Through external devices (for example, through files on a disk). Global variables – the program and the subroutine “know” in which variables the initial data is written, and in which results of the subroutine execution. Parameters of a subroutine – in the parameters of a subroutine, you can transfer the initial data and get the results of execution through them. External devices – theoretically, a program can write the initial data to a file, and a subroutine can read data from this file. Execution results can be passed in reverse order. If we are talking about low-level languages ​​or machine codes, then the data is transferred: 1) Through the processor registers. 2) Through the allocated cells of the RAM. 3) Through the stack. Processor registers – before calling the subroutine, the initial data is written to the predefined processor registers. After execution, the subroutine also writes the results to the predefined registers. Dedicated RAM cells – input and output data are written to pre-specified RAM addresses. Stack – can be compared to a revolving drum, data is pushed onto the stack one by one and then popped off the stack in reverse order.



One of the components of a person's success in our time is receiving modern high-quality education, mastering the knowledge, skills and abilities necessary for life in society. A person today needs to study almost all his life, mastering everything new and new, acquiring the necessary professional qualities.