1 Understand the working principle of ARM processor by learning ARM assembly language.
2 Write Bootloader in Assembly
The basic syntax of assembly here has been written in "ARM Embedded System Development". Here are some points that need special attention
When we learn assembly language, we are not required to write many complex programs in assembly language. That is impractical, and those can be written in C, which is a higher level language.
7 addressing modes:
1 immediate addressing ADD r0,r0,#1
2 register addressing ADD r0,r0,r1
3 Register indirect addressing LDR r0, [r1]
4-register indexing addressing: pre-indexing, automatic indexing, post-indexing
LDR r0,[r1,#4]
LDR r0,[r1,#4]!
LDR r0,[r1],#4
5 Stack addressing We usually use FD full decrement LDM {sp}! , {r1-r4}
For stack only
6-block copy addressing
LDMIA LDMIB LDMDA LDMDB
7Relative Addressing
BL label relative addressing
LDR pc, label or MOV pc, label absolute addressing
I will not introduce the specific instructions here. Here are some more:
1 In example LDMFD sp! {r1-r5, pc}^
When pc is added, adding ^ means copying spsr to cpsr.
2. Multiplication instructions are rarely used because they are inefficient. Even if they are used, they are replaced by displacement.
3AND is used to indicate zero, ORR is used to indicate 1, EOR is used to negate, and BIC is used to clear a bit (BIC is used to clear a bit of the comparison number, whichever bit is 1 becomes 0, which is the opposite of AND)
While TST is AND without result register and changes cpsr TEQ is XOR CMP is subtraction.
Next, let's talk about the focus of this lesson, the armlinux compiler gcc
Under win, armcc is used, while ours uses gcc
1 Any identifier ending with a colon is considered a label. When the label is a number from 0 to 9, it is a local label. Adding f after the local label indicates the label forward from the place where the label is referenced.
Adding b means backward
For example: subs r0, r0, #1
bne 1f
2. Use the section pseudo-operation to define a segment, followed by the segment name
The assembly system has predefined segment names. text is the code segment. data is the initialized data segment. bss is the uninitialized data segment (.bss must be before text)
3 Define the entry point, which is the start label by default. You can also use ENTRY (flag) to indicate the entry mark in the connection script. The connection script is introduced later.
.section .data
<...>
.section .bss
<...>
.section.text
.globl _start _start is global
_start: Code execution starts here.
4. .align 2(4,8,16) alignment
No error is reported if the .end terminator is not added
.include includes header files
.global defines a global symbol
Top 5 Compiler Tools
arm-linux-as
arm-linux-gcc
arm-linux-ld
arm-linux-objcopy
arm-linux-objdump
Introducing the steps to the birth of the next ARM program.
1. Write the program
2 Compile into .o file using arm-linux-gcc -c link.s -o link.o
If you use the -S option to compile a program written in C to generate an assembly file
3. Write a linker script and compile it into an ELF file: First, make it clear why you need to link: there are two points: 1. Address redirection. 2. Write a symbol table. There is a built-in default linker script in the gcc compiler, but it can only be loaded if there is an operating system. Because it is linked by the mapping address of the memory in the operating system. The target file of the gnu compiler is in ELF format. It consists of several sections. There are text segments, data segments, and bss segments. The task of the connector is to connect the text segments, data segments, and bss segments of multiple target files together. The linker script tells the connector what address to start putting these segments.
Such as link.lds
ENTRY(begin)
SECTION
{
.=0x30000000; means the target code starts at address 0x30000000
.text :{*(.text)}
.data :{*(.data)}
.bss :{*(.bss)}
}
Then generate an elf file through arm-linux-ld -nostadlib -o link.elf -Tlink.lds link.o main.o. Nostadlib means not to connect to the system library, -T means to use the link script. You can also use -Ttext address; address means the execution area address.
4 Generate a binary file. The binary file can be loaded into the memory
arm-linux-objcopy -o link.bin link.elf
5 Disassembly
You can also use objdump to disassemble
arm-linux-objdump -D link.elf > a.dis
arm-linux-objdump -D -b binary -m arm link.bin >a.dis
Previous article:Lesson 1: S3C2440 programming
Next article:Lesson 3: Light up the LED light on the development board
- Popular Resources
- Popular amplifiers
- 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)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
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
- What are the functions of the Internet of Vehicles? What are the uses and benefits of the Internet of Vehicles?
- Power Inverter - A critical safety system for electric vehicles
- Analysis of the information security mechanism of AUTOSAR, the automotive embedded software framework
- Brief Analysis of Automotive Ethernet Test Content and Test Methods
- How haptic technology can enhance driving safety
- Let’s talk about the “Three Musketeers” of radar in autonomous driving
- Why software-defined vehicles transform cars from tools into living spaces
- How Lucid is overtaking Tesla with smaller motors
- Wi-Fi 8 specification is on the way: 2.4/5/6GHz triple-band operation
- Wi-Fi 8 specification is on the way: 2.4/5/6GHz triple-band operation
- TI Cup 2019 National College Student Electronic Design Competition TI Processor Board Application Ten Questions and Answers
- What is the use of a diode in parallel with a pull-up resistor?
- Regarding the improvement suggestions after studying "PCB layout and thermal design system of high-density power system", please use the website as "Editor"...
- ESP-S3-12K (Part 2) ---- Let's power it up
- What to do next?
- Study on frequency requirements for 5G NR-V2X direct communication
- Solution to SensorTile.box not finding serial port using Unicleo-GUI
- The express delivery didn’t arrive for 6 days. I took a look and found out that the express delivery also misses home.
- [GD32L233C-START Review] - Transplanting Freertos real-time system
- [Warehouse temperature and humidity automatic control simulation system] 3. RSL10 BLE Mesh networking first experience