10. Learning ARM assembly

Publisher:幸福旅程Latest update time:2024-10-30 Source: cnblogsKeywords:ARM Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

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

  1. Startup code.

  2. Where high efficiency is required.

ARM assembly classification:

There are currently two commonly used ARM assembly instructions:

  1. ARM standard assembly: assembler for ARM company, suitable for use on Windows platform, such as ADS platform.

  2. 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.


Keywords:ARM Reference address:10. Learning ARM assembly

Previous article:11. Simple operation of assembly code
Next article:9.ARM addressing mode

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号