9. Mixed programming of ARM assembly and C

Publisher:bonbonoLatest update time:2023-07-11 Source: elecfansKeywords:ARM Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

9.1 Mixed programming of ARM assembly and C

9.1.1 Embedded assembly __asm

__asm("command")

For example, turn off/on the general interrupt switch CPSR


__asm ​​//Use variable names in C instead of registers

{

    MOV was,x

    ADD y,var,x/y

}

Register names in inline assembly language are treated by the compiler as variables in C or C++ language, so register names appearing in inline assembly do not necessarily correspond to physical registers with the same name.

These register names must be declared before use, otherwise the compiler will prompt a warning message


9.1.2 Assembly access to global variables in C

【1】Use IMPORT to declare global variables


【2】Use LDR to get its address


AREA globals, CODE, READONLY

EXPORT asmadd

IMPORT gvar; declare external variable gvar

asmadd

LDR R1, =gvar; load variable address

LDR R0, [R1]; read data

ADD R0, R0, #1; add 1 operation

STR R0, [R1]; save variable value

MOV PC, LR

END


9.1.3 ATPS(ARM-Thumb Produce Call Standard)

ATPCS (ARM-Thumb Produce Call Standard): Basic rules for subroutine calls in ARM programs and Thumb programs

Rules for using registers during subroutine calls

Use R0-R3 to pass parameters, and R4-R11 to save local variables.

Data stack usage rules

The stack uses full decrementing (FD). When there are more than 4 parameters, the excess part uses the stack to transfer parameters, and the return value is stored in R0.

9.2 ARM assembly THUMB2 instruction set

9.2.1 ARM THUMB THUMB2

ARM instructions: 32-bit, supports all functions, all instructions can be executed conditionally

THUMB: 16 bits, cannot access coprocessors, privileged instructions and special function instructions, only B instructions can be executed conditionally

THUMB2: Thumb-2 is a superset of the 16-bit Thumb instruction set. The instructions are 32-bit or 16-bit. It is different from the ARM instruction 32-bit encoding format. It is up to the assembler to decide whether to use 16-bit instructions or 32-bit instructions.

9.2.2 ARMV8 (64bit architecture)

ARMv8 provides two Execution States, AArch32state and AArch64 state, and no longer distinguishes between ARM state and THUMB state.

In the AArch32 state, two instruction sets A32 (32bit) and T32 (16/32bit) are provided. The two instructions are switched through BX.

In the AArch64 state, only the A64 instruction set is supported, and the fixed length is 32bit.

ARMV8 provides different run levels: Exception Level and Security (EL0(app), EL1, EL2, EL3), analogous to X86's Ring0-ring3(app)

9.2.3 CORTEX-M3

Cortex-M3 only supports Thumb-2 instructions. The Thumb-2 instruction set will be explained in detail in the STM32 microcontroller course.


Keywords:ARM Reference address:9. Mixed programming of ARM assembly and C

Previous article:10. S3C2440 development resources
Next article:8. ARM assembler format and program control

Recommended ReadingLatest update time:2024-11-16 09:29

ARM/DSP multi-machine I2C communication solution
introduction In many embedded control systems, the system must complete a large amount of information collection and complex algorithms, and also realize precise control functions. The ARM9 microcontroller running the embedded Linux operating system is used to complete signal collection and implement the upper-level
[Microcontroller]
ARM/DSP multi-machine I2C communication solution
ARM9 (S3C2440) clock and timer
Clock concept 1. Clock pulse: A pulse signal that is continuously emitted at a certain voltage amplitude and a certain time interval. 2. Clock frequency: the number of clock pulses generated per unit time (such as one second). Clock function The clock signal is the basis of sequential logic (for example, some
[Microcontroller]
ARM7 memory structure and external flash
1. Words and Halfwords of Memory 1. Two consecutive bytes starting from an even address constitute a half-word. 2. Four consecutive word orders of addresses divisible by 4 constitute a word The length of an ARM instruction is exactly one word, and the length of a Thumb instruction is exactly one half word. 2.
[Microcontroller]
C&K introduces SDS ultra-low current series switches
WALTHAM, Mass. — July 29, 2022 — C&K, a leading manufacturer of high-quality electromechanical switches, has introduced the SDS Series ULC (Ultra Low Current) Detect Switch. This switch was developed to reduce energy consumption in battery-powered devices. As more and more devices rely on batteries, designer
[Power Management]
C&K introduces SDS ultra-low current series switches
Build ARM development environment with Eclipse under Ubuntu
Step 1: Install JRE and Eclipse       For detailed steps, please refer to: http://blog.csdn.net/ex_net/article/details/7251664   Step 2: Install arm -linux-gcc and arm-linux-g++    (1) Copy arm-linux- gcc -4.3.2.tgz to the /home/tools directory, and then decompress it to the root directory/                #   tar -x
[Microcontroller]
Build ARM development environment with Eclipse under Ubuntu
Ultrasonic PIC microcontroller C program
The microcontroller source program is as follows: //////////////////////////////////////////////////////////////////////////////// // //     PIC16F877 + HC-SR04 + LCD03 example //     Written October 2008 , using HITECH PIC16 compiler //  //                 Note - assumes a 20MHz crystal, which is 5MHz timer clock //
[Microcontroller]
Keil C51 keyword sfr sbit related knowledge
SFR is not a keyword in the standard C language, but Keil provides a new keyword for direct access to 80C51. Function: Keywords used to define hardware register addresses, which have the function of defining hardware characteristics. For example: sfr P0 = 0x80; sfr P1 = 0x90;
[Microcontroller]
STM32CubeMX learning tutorial 10: Hardware I2C reading and writing AT24C02
There is a long-standing saying on the Internet that STM's I2C has bugs and is not easy to use. Indeed, many people have encountered various problems in actual applications, so most people use software to simulate IIC. With STM32CubeMX, we can try to use hardware I2C. The official optimization can't be wrong, right?
[Microcontroller]
STM32CubeMX learning tutorial 10: Hardware I2C reading and writing AT24C02
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号