Arm Common Assembly instruction learning

Source: Internet
Author: User

Previously, the arm ide tool used the arm standard assembly language. Now we need to use the GNU tool. Of course we need to understand the differences between the GNU arm assembly. In fact, it is very simple. You can simply browse the document and then look at the program, or you can read the GNU arm assembly program with a hard head, you won't have much time to complete without a teacher. My personal is relatively forgetful. If you translate the document, you can give yourself a reason to avoid forgetting.

The source program statements of ARM assembly language are generally composed of commands, pseudo operations, macro commands, and pseudo commands. the design basis of ARM assembly language is Assembly pseudo commands, assembly pseudo operations, and macro commands.

Currently, two commonly used ARM compiling environments are available:
ARMASM: The CodeWarrior compiler is used in the IDE of ARM. The vast majority of developers in windows are using this environment, fully in accordance with ARM's regulations;
Gnu arm asm: the ARM version of the GNU tool, which is slightly different from ARMASM;

There are many books and articles on CodeWarriror ARM Assembly. This article assumes that you fully understand ARMASM. Here we only describe the gnu arm assembly and give a description of ARMASM. This article translated from: gnu arm runner er Quick Reference. I am at a limited level. errors are inevitable. Please indicate the source. The original English address is unknown.

Gnu arm Assembly Quick Start

Any assembly line has the following structure: [<label >:] [<instruction or Directive >}@ comment
[<Tag >:] [<command >}@ note in the GNU arm assembly, any tag ending with a colon is considered as a tag, not necessarily at the beginning of a line. The following is a simple example. This assembler defines a "add" function, which returns the sum of two parameters:. Section. Text and "X"
. Global add @ give the symbol add external Linkage
Add:
Add r0, R0, R1 @ add input arguments
MoV PC, LR @ return from subroutine
@ End of Program Gnu arm Assembly pseudocommandsSome GNU Arm Assembly pseudocommands are listed below, and corresponding descriptions are given.
. ASCII "<string>" defines strings in the Assembly and allocates storage space for them (similar to the DCB function in armasm ).
. Asciz "<string>" is similar to. ASCII, but no storage space is allocated. . Balign <power_of_2 >{, <fill_value >{, <max_padding> }}
Fill the value in the memory in a certain arrangement. (This command is similar to align in armasm ).
Power_of_2 indicates the arrangement mode. The value can be 4, 8, 16, or 32. The unit is byte;
Fill_value is the value to be filled;
The maximum filling limit of max_padding. If the number of bytes filled by the request exceeds this value, the request is ignored. . Byte <byte1 >{, <byte2> }... Define one or more bytes and allocate space for them (similar to the DCB of armasm ). . Code <number_of_bits> sets the instruction width. 16 indicates Thumb and 32 indicates ARM assembly.
(Same as CODE16 and CODE32 in armasm ). . If
. Else
. Endif
Precompiled macro (same as if else endif in armasm ). The end mark of the. end Assembly file, which is often omitted .. Endm macro end flag.
The. exitm macro jumps out.
. Macro <name >{< arg_1 }{, <arg_2> }... {, <Arg_N>}
Define a macro named name. arg_xxx is the parameter.
It must end with the corresponding. endm.
You can use. exitm to jump out of the macro from the middle. (Same as MACRO, MEND, and MEXIT in armasm ).
You must use "/<arg>" when using macro parameters ". For example:
[CODE]. macro SHIFTLEFT a, B
. If/B <0
MOV/a,/a, ASR #-/B
. Exitm
. Endif
MOV/a,/a, LSL #/B
. Endm. rept <number_of_times> executes the code segment number_of_times before endr cyclically.
(Similar to WEN in armasm). irp <param >{,< val_1 >}{, <val_2> }...
The code segment before the loop execution. endr, And param take the values given later in sequence.
The parameter must be '/<param>' in the code segment that executes the loop .. Endr end loop (similar to WEND in armasm)... equ <symbol name> and <value> assign values to a label, similar to # define in C. (Same as EQU in armasm). err compilation Error Report will cause compilation termination. . Global <symbol> indicates the global declaration flag, so that the declared label can be used externally. (Same as EXPORT in armasm ). . Hword <short1 >{, <short2> }...
Insert a 16-bit data queue. (Same as DCW in armasm). ifdef <symbol> If <symbol> is defined, the quick code will be compiled. End with. endif.
. Ifndef <symbol> If <symbol> is not defined, the quick code will be compiled. End with. endif. . Include "<filename>" contains the file. (Same as INCLUDE in armasm or # I nclude in C) <register_name>. req <register_name>
Define a register. The left side of req is the defined register name, and the right side is the actually used register.
(Similar to RN in armasm)
Example: acc. req r0 [CODE]. section <section_name >{, "<flags> "}
Start a new code or data segment .. Text, code segment;. Data, initialized data segment;. BSS, not initialized data segment.
These segments all have default flags that can be recognized by the connector. (Same as the area in armasm ).
The following section lists the allowed segments in the ELF format.
<Flag> meaning
A allowed segment
W writable segments
X execution segment. Set <variable_name>, <variable_value> variable value assignment. (Same as Seta in armasm). Space <number_of_bytes >{,< fill_byte>}
Allocate the data space of number_of_bytes bytes and fill in the value of fill_byte. If this value is not specified, it is filled with 0 by default.
(Same as the space function in armasm). Word <word1 >{, <word2> }...
Insert a 32-bit data queue. (Same as the DCD function in armasm) several common segment codes are basically irrelevant to the compiler/processor (flat mode ):
. Text-code segment
. Const-read-only data segment (Some compilers do not use this segment, and read-only data is incorporated into the. Data Segment)
. Data-read/write data segment
. BSS-heap

Gnu arm compiles special characters and syntaxComment symbol in the code line :'@'
Comment on the entire line :'#'
Statement separator :';'
Direct operand Prefix: '#' or '$'. arm is compiled in arm format, same as code32
. Thumb is compiled in thumb format, same as code16
. Code16 is compiled in thumb format
. Code32 is compiled in arm formatPost:For more detailed instructions, see ARM Architecture Reference Manual, Addison-Wesley ISBN 0-201-73719-1

Translator:The important part has been translated. I think it is not important to translate it, such as force_thumb and register name.

Reprinted from: http://patton.spaces.eepw.com.cn/articles/trackback/item/28951

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.