MasterProgramBefore calling a subroutine, you must pass the raw data to be processed by the subroutine, that is, prepare the entry parameters for the subroutine.
There are four common parameters passed
1. Register Method
The Register Method stores the entry and exit parameters in the agreed register.
Advantages: Fast Reading of Data Transmission books, convenient programming, and memory saving.
Disadvantage: when too many parameters are passed, the number of registers is limited and the register is frequently used.
Applicable: subprograms with fewer parameters
2. Agreed unit method:
As the name implies, the agreed unit method puts both the entry and exit parameters in the pre-agreed unit.
Advantage: no register is occupied, the number of parameters is arbitrary, and the data to be processed by each subroutine and the sent structure have independent storage units.
Disadvantage: However, using a certain number of storage units increases the difficulty of variable definition in programming.
3. Stack Method
The stack method uses the stack to pass parameters.
Advantage: parameters do not occupy registers or storage units. The parameters are stored in the public stack. After processing, the customer recovers. The number of parameters is generally unlimited.
Disadvantage: Because parameters and subprograms are mixed together, you must calculate its position in the stack carefully when accessing parameters. Pay attention to the resumable storage and restoration.
4. Address Table Method
In this way, a parameter table composed of parameters is placed in a certain storage area. As long as the main program and subroutine agree on the first address and content of the storage area, in the main program, the parameters are passed to the address table. In the subroutine, the operation can be completed based on the parameters specified in the address table.
C. Pascal and others use the stack method to pass Parameters
When a program written in assembly language calls a subroutine written in other languagesCodeWhen a subroutine module is provided for another language, programs written in assembly language must comply with the parameter passing rules of the corresponding advanced language. The change principle must be followed when compilation languages and other languages are mixed.