Learning ARM assembly is very necessary. Learning ARM assembly is not to write programs in assembly in the future, but to understand and modify it. Because in the later projects related to the kernel and bootloader, some codes will be written in assembly. In the bootloader, once the system is powered on, the first program to run needs to initialize the CPU and coprocessor. At this time, there is no environment for C language to run because there are no stacks and other conditions. The same is true in the kernel. The reason for using assembly is because of its recognized efficiency. When the system is just powered on or when an efficient programming language is needed in a program, assembly will be considered for implementation. Just like C language, it can embed assembly code to improve operating efficiency.
Summary: Two places where assembly is used
-
Startup code.
-
Where high efficiency is required.
ARM assembly classification:
There are currently two commonly used ARM assembly instructions:
-
ARM standard assembly: assembler for ARM company, suitable for use on Windows platform, such as ADS platform.
-
GNU Assembler: Assembler for the GNU cross-compilation tool chain, suitable for Linux development platforms.
In fact, the syntax of ARM standard assembly and GNU assembly is similar, except that GNU assembly code is lowercase and ARM standard assembly code is uppercase. There are also some minor differences.
GNU assembly code basic framework: Figure 1-1:
.section .data
.section .bss
.section .text //.text indicates that the following is a code segment
.globl _start
_start: //Entry point of ARM assembly, needs to be declared as global using .global so that external files can use this mark
Figure 1-1
If there is no initialized data or uninitialized data in the project, the .section before .text is also omitted during the actual compilation. The final assembly program framework is as follows: 1-2:
.text
.global _start
_start:
Figure 1-2
Create a basic assembler framework:
First, write the code for start.S: Figure 1-3:
.text
.global _start
_start:
mov r1,#11
mov r2,#22
mov r3,#33
Figure 1-3
The assembler code start.S has been written above. The next step is to write its Makefile. However, in this Makefile project, since there is only one start.S assembly file, the lds link file is not used to avoid wasting resources. The direct link address is specified in the format of -Ttext address. The final Makefile code: Makefile: Figure 1-4:
all: start.o
arm-linux-ld -Ttext 0x50008000 -o gboot.elf $^
%.o : %.S
arm-linux-gcc -g -o $@ $^ -c
.PHONY: clean
clean:
rm *.o *.elf
Figure 1-4
The whole simple process only requires two files: Figure 1-5:
Figure 1-5
The next step is to import eclipse, configure the debugging environment, and start debugging.
The linking process is not detailed here. If you have any questions, please refer to Section 5: Eclipse Integrated Development Environment. After linking, bare metal debugging was successfully performed and the assembly code just written was entered: Figure 1-5:
Figure 1-5
Press F6 to debug in single step, and you can see that it has run to the second assembly code. Figure 1-6:
Figure 1-6
After running, you can see that the value of r1 is assigned to 11. Figure 1-7:
Figure 1-7
Then press F6 to execute the next assembly instruction. Figure 1-8:
Figure 1-8
As you can see above, the bare metal code runs normally.
Previous article:11. Simple operation of assembly code
Next article:9.ARM addressing mode
- Popular Resources
- Popular amplifiers
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
- Keysight Technologies Helps Samsung Electronics Successfully Validate FiRa® 2.0 Safe Distance Measurement Test Case
- Innovation is not limited to Meizhi, Welling will appear at the 2024 China Home Appliance Technology Conference
- Innovation is not limited to Meizhi, Welling will appear at the 2024 China Home Appliance Technology Conference
- Huawei's Strategic Department Director Gai Gang: The cumulative installed base of open source Euler operating system exceeds 10 million sets
- Download from the Internet--ARM Getting Started Notes
- Learn ARM development(22)
- Learn ARM development(21)
- Learn ARM development(20)
- Learn ARM development(19)
- Learn ARM development(14)
- IoT wireless communication data transmission module: multi-host gateway working mode, understand it in one article
- [RT-Thread reading notes]——The definition of threads and the implementation of thread switching
- How to read and write attributes through the characteristic uuid in sdk!
- MSP430FR5994 Hardware SPI Exception
- In what fields can power amplifiers be used?
- [Runhe Neptune Review] Five PWM
- How to use the wireless transceiver module
- Understanding of MSP430G2553
- A lightweight and precise positioning algorithm based on multiple inertial measurement units (LSM6DSOX)
- PT1000 circuit help