Part 1: Introduction to ARM assembly language
Part 2: Analysis of the process of generating ARM assembly programs from C/C++ programs Part
3: ARM assembly language program structure
Part 4: Addressing methods of ARM processors
Part 5: ARM instruction set and Thumb instruction set
Part 6: NEON instruction set and VFP instruction set
The ARM assembly of the Android platform is in the GNU ARM assembly format, and the assembler used is GAS (GNU Assembler). GAS has its own set of syntax structures. For details, please refer to the official manual of GAS syntax structure.
Let's first look at a complete ARM assembly program:
C code:
#includeint main(int argc, char* argv[]){ printf("Hello ARM!\n"); return 0; }
The corresponding assembly code:
.arch armv5te .fpu softvfp .eabi_attribute 20, 1 .eabi_attribute 21, 1 .eabi_attribute 23, 3 .eabi_attribute 24, 1 .eabi_attribute 25, 1 .eabi_attribute 26, 2 .eabi_attribute 30, 6 .eabi_attribute 18, 4 .file "hello.c" .section .rodata .align 2 .LC0: .ascii "Hello ARM!\000" .text .align 2 .global main .type main, %function main: @args = 0, pretend = 0, frame = 8 @frame_needed = 1, uses_anonymous_args = 0 stmfd sp!, {fp, lr} add fp, sp, #4 sub sp, sp, #8 str r0, [fp, #-8] str r1, [fp, #-12] ldr r3, .L3 .LPIC0: add r3, pc, r3 mov r0, r3 bl puts(PLT) mov r3, #0 mov r0, r3 sub sp, fp, #4 ldmfd sp!, {fp, pc} .L4: .align 2 .L3: .word .LC0-(.LPIC0+8) .size main, .-main .ident "GCC: (GNU) 4.4.3" .section .note.GNU-stack,"",%progbits
The following section describes the structure of this code.
1. Processor architecture definition
.arch armv5te @processor architecture .fpu softvfp @coprocessor type .eabi_attribute 20, 1 @Interface attribute .eabi_attribute 21, 1 .eabi_attribute 23, 3 .eabi_attribute 24, 1 .eabi_attribute 25, 1 .eabi_attribute 26, 2 .eabi_attribute 30, 6 .eabi_attribute 18, 4
1.1 Processor Architecture
.arch specifies the ARM processor architecture. armv5te means that the code of this program can run on processors with armv5te architecture.
1.2 Coprocessor Type
.fpu specifies the type of coprocessor. softvfp means using the floating point library to simulate coprocessor operations. You can also use vfpv2 and vfpv3 to specify the built-in coprocessor.
1.3 Interface attributes
.eabi_attrbute specifies some interfaces.
EABI (Embedded Application Binary Interface) is a set of interface specifications specified by ARM, and the Android system implements it.
Two-part definition
.file "hello.c" .section .rodata .align 2 .LC0: .ascii "Hello ARM!\000" .text .align 2 .global main .type main, %function main: @args = 0, pretend = 0, frame = 8 @frame_needed = 1, uses_anonymous_args = 0 stmfd sp!, {fp, lr} add fp, sp, #4 sub sp, sp, #8 str r0, [fp, #-8] str r1, [fp, #-12] ldr r3, .L3 .LPIC0: add r3, pc, r3 mov r0, r3 bl puts(PLT) mov r3, #0 mov r0, r3 sub sp, fp, #4 ldmfd sp!, {fp, pc} .L4: .align 2 .L3: .word .LC0-(.LPIC0+8) .size main, .-main .ident "GCC: (GNU) 4.4.3" .section .note.GNU-stack,"",%progbits
The definition format of the ARM middle section is as follows:
.section name, "flags", %type, flag_specific_arguments
- name: segment name
- flags: Segment attributes, such as read, write, and executable.
- type: The type of segment, such as progbits means that the segment contains data, and note means that the data contained in the segment is not used by the program itself.
- flag_specific_arguments: Specifies some platform-dependent parameters.
3. Notes and Numbers
GNU ARM supports two ways of adding comments.
/* */ type comments
/* args = 0, pretend = 0, frame = 8 */ /* frame_needed = 1, uses_anonymous_args = 0 */
@-type annotation
@args = 0, pretend = 0, frame = 8 @frame_needed = 1, uses_anonymous_args = 0
Four assembler instructions
.file "hello.c" .section .rodata .align 2 .LC0: .ascii "Hello ARM!\000" .text .align 2 .global main .type main, %function
All instructions in the program that start with . are assembler instructions. Assembler instructions are related to the assembler and do not belong to the ARM instruction set.
- .file: Specifies the source file name.
- .align: Specifies the alignment of the code, and the value following it is a power of 2.
- .ascii: declares a string.
- .global: declares global symbols, which are symbols accessible outside this program.
- .type: Specifies the type of the symbol.
- .word: used to store address values.
- .size: Sets the size of the specified symbol.
- .ident: Compiler identifier, no practical use.
Five subroutines and parameter passing
A subroutine represents an independent function in the code. In many cases, a subroutine and code are the same concept. The way to declare a function in assembly is as follows:
.global function name .type function name%Function Function name: ... Function body ...
Then during the function call, the parameter passing method is as follows:
ARM assembly language stipulates that the four registers R0 to R3 are used to pass the first to fourth parameters of a function call, and the parameters beyond that are passed through the stack. The R0 register is used to store the return value of a function call. The called function does not need to restore the contents of these registers before returning.
Previous article:ARM assembly language series based on Android VI: NEON instruction set and VFP instruction set
Next article:ARM assembly language series based on Android 5: ARM instruction set and Thumb instruction set
- Popular Resources
- Popular amplifiers
- Learn ARM development(19)
- Learn ARM development(14)
- Learn ARM development(15)
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Learn ARM development(19)
- Learn ARM development(14)
- Learn ARM development(15)
- Analysis of the application of several common contact parts in high-voltage connectors of new energy vehicles
- Wiring harness durability test and contact voltage drop test method
- From probes to power supplies, Tektronix is leading the way in comprehensive innovation in power electronics testing
- From probes to power supplies, Tektronix is leading the way in comprehensive innovation in power electronics testing
- Sn-doped CuO nanostructure-based ethanol gas sensor for real-time drunk driving detection in vehicles
- Design considerations for automotive battery wiring harness
- Do you know all the various motors commonly used in automotive electronics?
- EEWORLD University ---- Control system of 100 quantum bits
- What is the function of this solder joint on the PCB?
- Can I change my nickname in the forum?
- GD32L233C-START Review——03_2.CoreMark Test, RT-Thread-Nano Porting
- A detailed guide to the Industrial Internet of Things: From risks to benefits
- How to implement remote monitoring of wind turbines in wind farms?
- The difference between USART, USI, USCI and eUSCI serial communication modules in MSP430 microcontroller (updated on March 4, 2019)
- Answer questions to win prizes | ADI Technology Express - Industrial Automation Control and Edge Computing
- MSP432P401R MSP432P4xx: Falcon Series
- [TI recommended course] #Live replay: TI mmWave millimeter wave radar application in automobiles#