ARM bare metal program development (10): C language environment initialization

Publisher:SereneWhisperLatest update time:2020-03-28 Source: eefocusKeywords:ARM Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

Part 1 Stack Initialization


1. Full/Empty Stack


1.1 Full stack: When the stack pointer SP always points to the last data pushed into the stack (used by ARM)


1.2 Empty stack: When the stack pointer SP always points to the next empty location where data will be placed


 


2. Stack Up/Down


According to the moving direction of the SP pointer when pushing into the stack: if it is from low to high, it is stacking up, and from high to low, it is stacking down (used by ARM)



3. Stack Frame


Definition: The part of the stack used by a function is called a stack frame


Two boundaries of the stack frame: fp(r11) and sp(r13)


3. Stack Function


3.1 Saving local variables


3.2 Passing parameters: When the number of parameters to be passed is greater than 4, use the stack to pass them, otherwise, use general registers to pass them


3.3 Passing Register Values


Part 2 BSS segment 1 initialization


Part 3 Jump from assembly to C


Jump mode: absolute jump


Part 4 C and assembly mixed programming


1. Where to use assembly: 1. Where efficiency is high; 2. Where direct hardware operation is required (such as coprocessor operation)


2. Calling C in assembly: directly assign the entry pointer of C to PC


(C code is in a separate C file)


3. Calling assembly from C: Declare the label as .global in the assembly file, and then call it directly as a function in C.


(Assembly code is in a separate file)


IV. Embedded Assembly in C


4.1 Format


__asm__(


Assembly statement part


: Output section


: Input part


: Destruction description section


);


//Example 1


void write_p15_c1(unsigned long value)


{


    __asm__(


“mcr p15, 0, %0, c1, c0, 0n” @%0 is a placeholder parameter


:


:"r" (value) @r indicates a general register


);


}


 


//Example 2


usigned long read_p15_c1 (void)


{


  usigned long value


__asm__(


  "mrc p15, 0, %0, c1, c0, 0n" The value read from @c1 is sent to Value


    :"=r" (value) @'=' indicates a write-only operand, used for output


    :


    :”memory”


);


return value;


}


4.2 Optimization


In programming, volatile is used to tell the compiler not to optimize the following part of the code (especially when operating on hardware)

Keywords:ARM Reference address:ARM bare metal program development (10): C language environment initialization

Previous article:TQ2440 development board learning record (2) --- Setting up the stack and calling C functions
Next article:The role of the stack in the program (ARM structure)

Recommended ReadingLatest update time:2024-11-16 15:56

Design of CAN/PCI Intelligent Communication Card Based on ARM Controller LPC2294
introduction LPC2294 is a powerful, ultra-low power 32-bit microcontroller with ARM7TDMI core launched by PHILIPS . It has rich on-chip resources and can fully meet the needs of general industrial control. At the same time, it can also reduce the complexity of system hardware design and improve system st
[Industrial Control]
Design of CAN/PCI Intelligent Communication Card Based on ARM Controller LPC2294
How does ARM implement absolute address jump?
Analysis based on b jump instruction, ldr pseudo instruction, ldr load instruction The following scenarios require 1. After executing some instructions from Stepingstone, you need to jump to SDRAM for execution. The prerequisite is that you must first copy the code in NAND FLASH to SDRAM before you can jump to SDR
[Microcontroller]
ARM embedded development software learning steps
    For many beginners, to deeply learn arm+linux, you need to consider from two directions, software and hardware. About in-depth learning of arm+linux, software learning:     Software     1. Bootloader     1) Can be written and compiled based on ADS and GCC. (Besides the difference in the use of assembly and compil
[Microcontroller]
When will the chip shortage end? ARM CEO gives the answer
ARM CEO Simon Segars said the global chip shortage is very complex to resolve and expects current supply chain disruptions to continue until 2022. According to the executive, the semiconductor industry is now spending $2 billion per week to increase production capacity and expects this investment to result in a 50%
[Semiconductor design/manufacturing]
IAR for ARM Series Tutorial (III)_Menu (I)
Ⅰ. Write in front IAR software has multiple series versions, such as MSP430, STM8, etc., but in order to make the software "compatible" in use, the multiple series software launched by IAR have similarities in many places, including the content of IAR menu. Therefore, the content of this article is also applicable to
[Microcontroller]
IAR for ARM Series Tutorial (III)_Menu (I)
New future chips take off, Arm future chips help youth science and technology education
    Under the guidance of the China Electronics Society and with the support of the Shanghai Electronics Society, the launch ceremony of the New Future - Core Flying 2019 Arm Future Core International Challenge and the National Youth Electronic Information Intelligent Innovation Competition International Station (he
[Microcontroller]
New future chips take off, Arm future chips help youth science and technology education
Azure ARM (11) Create a virtual machine and configure a load balancer in ARM mode
  In the previous chapters, we did the preparation work:   1. Create an ARM Resource Group called LeiResourceGroup   2. Create an ARM Storage Account called leistorageaccount   3. Create an ARM Virtual Network called LeiARMVNet       In this chapter, I will introduce how to create a virtual machine VM in ARM mode. It
[Microcontroller]
Azure ARM (11) Create a virtual machine and configure a load balancer in ARM mode
Research on computer mouse control system based on ARM
1 Working principle of computer mouse Six groups of infrared sensors are installed around the computer mouse to sense the left, left front, front, right front and right respectively. The transmitter emits infrared rays of a certain frequency. The receiver judges whether there are obstacles through the reflected waves
[Microcontroller]
Research on computer mouse control system based on ARM
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号