Parameter transfer method between the main program and subprogram of Assembly Language

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.