Linux assembly and C mutual call, Linux assembly call

Source: Internet
Author: User

Linux assembly and C mutual call, Linux assembly call

I. Introduction

There are two methods for calling assembly in C language: 1. Using embedded assembly 2. Using the compilation link.

 

Ii. Basic Knowledge

There are two main problems to solve for the interfaces of C and assembly language.

1. parameter transfer between the caller and the called

Normally, defining a function always requires it to complete some functions, and a useless function will be meaningless. These functions are often part of larger functions, and functions must be more or less associated with the outside world (a function that is completely unrelated to the outside world is also meaningless) (The latency function also consumes time and time is also a type of external resource.) For example, if you want to transmit some data for processing, the system returns the processing result after processing. This data transmission can be implemented in two ways: the first is that the outside world directly transmits the data to the function, and the second is that the function itself retrieves the data from the outside world.

For the first type:

This kind of data transfer is completed through the stack, which is a implicit method. The implicit operation is that the call starts from the last parameter in the call program parameter table and is automatically pushed into the stack in turn; after all parameters are pushed to the stack, the return address (breakpoint) after the invocation of the called program is automatically pushed to the stack, so that after the completion of the called program, the system can return the correct position of the main program and continue the execution.

For the second type:

For the second model, a public region must be opened, and both the caller and the called must be able to access this region.

 

2. Description and establish the connection between the caller and the called user

To establish the connection between the call and the called module, the called assembler applies global, indicating that it can be called by the external module; the calling program should predefine the name of the external module to be referenced.

 

Refer:

http://blog.chinaunix.net/uid-20797642-id-2495231.htmlhttp://www.cnblogs.com/shenlian/archive/2011/05/17/2049441.html

 

Iii. Instances

1. 32-bit: Linux assembly and C call each other

http://www.linuxidc.com/Linux/2012-07/65757.htm

 

Iv. FAQs

1. The following

Linux AT&T assembly Error: invalid instruction suffix for 'push'

Solution:

http://www.2cto.com/os/201310/253276.html

Related Article

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.