An assembly language learning note in IAR arm

Source: Internet
Author: User

Calm down to a special review of the RTOs, take Mqx-lite to start, re-read the code, record drip, for summary. 1. Pre-compilation

(1) commonly used precompiled directives such as # define and # include are also available in assembly files.

Precompiled directives are implemented by the precompiled compiler, #define执行是在编译器的符号表中建立新的符号 (and assigned values, corresponding to the precompiled instruction Equ of assembly language), and # include only replaces the contents of the containing file. Although the pre-compiler itself is often integrated into the compiler, it is actually not as close to the language-related compilers as we think.

The C-style precompiled directives that can be used in the IAR assembly are:

#define, #elif, #else, #endif, #error, #if, #ifdef, #ifndef, #include, #line, #message, #pragma, #undef

They are used in exactly the same way as in the C language.

#pragma会被汇编的预编译器忽略.

#error在汇编的预编译器处理过程中将引发一个错误.

(2) C Language-compatible annotations

Use the traditional ";" in the Assembly source code Comments are also possible, but the C-language "/* ... * *" comment and "//" are also supported in the IAR assembly source file. It should be noted that strictly speaking "//" is a C + + annotation style, and can not be classified as pure C, and in the current MISRA-C standard is not recommended.

In fact, the C-style pre-compiler in the IAR will pre-compile the assembly source files prior to compilation, so in the IAR Assembler Reference Guide (hereinafter referred to as Ewa_ RM) Description of a C-style and assembly language pre-compilation instructions can not be mixed nested, if the C-style precompiled instructions are nested in the compilation of pre-compiled instructions to avoid the C language precompilation, then in the compilation of pre-compiled processing, their existence will be considered an error. Similarly, in the context of the C-style precompilation, such as the use of the assembly-style annotation in the # define command, this will also be C-precompiled 2. Macro

Although IAR Arm's assembly language is compatible with the C-language macro definition (#define), the IAR assembly itself has its own macro definition.

In the new version of Mqx-lite, there is no macro (EWA_RM-P82) that uses the IAR assembly based on MQX tradition, but instead uses # define and CFI. For a # define before it has been said, focus now on CFI.

CFI is the abbreviation for Call Frame information, which is described in Ewa_rm (P105):

"When debugging an application using C-spy, the user can see the contents of the call stack, which is the other function chain that invokes the current function. To implement this feature when compiling a C source file, the compiler provides debugging information to describe the distribution of the call frame, especially the information that holds the return address. ”

"When you want to see the call stack information when debugging a function written in assembly language, you can use the CFI Directive modifier function in assembly language to achieve equivalent functionality."

That is, the CFI command is purely for debugging purposes. Considering the compatibility of the program, the CFI is ignored in the process of parsing the code, and the debugging of the assembly part is skipped in the actual application.

This is affixed to the macro (asm_mac.h) defined in Mqx-lite using the assembly:

#define ASM_PREFIX (x) x
#define ASM_EXTERN (label) EXTERN label
#define ASM_PUBLIC (label) public label
#define ASM_LABEL (label) label
#define ASM_EQUATE (label, value) label EQU value
#define ASM_SET (label, value) Asm_label (label) SET value
#define ASM_ALIGN (value) Alignrom VALUE/4
#define ASM_CONST16 (value) DC16 value
#define ASM_CONST32 (value) DC32 value
#define ASM_LABEL_CONST32 (label, value) Asm_label (label) DC32 value
#define ASM_CODE_SECTION (name) section Name:code (4)
#define ASM_CODE_SECTION_NOOPT (name) section Name:code (4): ROOT
#define ASM_DATA_SECTION (name) section Name:data (4)
#define Asm_end END

#define Asm_comp_specific_directives

#define指令的右值是IAR汇编中可用的关键字和命令. The last sentence of the definition of macro to use more special instructions, it seems that the positioning of the mqx-lite is not much of portability ah.

The definition of CFI is:

/* CFI annotations for public symbols called from C code */
CFI Names CFINames0
CFI stackframe CFA R13 DATA
CFI Resource r0:32, r1:32, r2:32, r3:32, r4:32, r5:32, r6:32, r7:32
CFI Resource r8:32, r9:32, r10:32, r11:32, r12:32, r13:32, r14:32
CFI Endnames CFINames0

CFI Common CFICommon0 Using CFINames0
CFI Codealign 2
CFI Dataalign 4
CFI returnaddress R14 CODE
CFI CFA r13+0
CFI R0 Samevalue
CFI R1 Samevalue
CFI R2 Samevalue
CFI R3 Samevalue
CFI R4 Samevalue
CFI R5 Samevalue
CFI R6 Samevalue
CFI R7 Samevalue
CFI R8 Samevalue
CFI R9 Samevalue
CFI R10 Samevalue
CFI R11 Samevalue
CFI R12 Samevalue
CFI R14 Samevalue
CFI Endcommon CFICommon0

/* Note that these macros should is on the beggining of the line when used
in assembler code. Prepend allways by at least one space.
(is not a issue in ewarm 6.40.x, space seems to is needed in 6.50.x) */
#define ASM_PUBLIC_BEGIN (name) CFI Block cfiblock_# #name Using CFICommon0
#define ASM_PUBLIC_FUNC (name) CFI Function name
#define ASM_PUBLIC_END (name) CFI Endblock cfiblock_# #name

This part of the code is put here first, although it is to be ignored, but should be forgotten.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.