This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| en:multiasm:paarm:chapter_5_2 [2025/03/07 10:08] – eriks.klavins | en:multiasm:paarm:chapter_5_2 [2025/12/02 21:31] (current) – eriks.klavins | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| ====== ARM Assembly Language Specifics ====== | ====== ARM Assembly Language Specifics ====== | ||
| - | All assembly language | + | Before starting programming, |
| + | The symbol ‘@’ is used to create a comment in the code till the end of the exact line. Some other assembly languages use ‘;’ to comment, but in ARM assembly language, ‘;’ indicates a new line to separate statements. The suggestion is to avoid the use of this ‘;’ character; there will be no such statements that would be divided into separate code lines. Multiline comments are created in the same way as in C/C++ programming languages by use of ‘/*’ and ‘*/’ character combinations. However, it is better | ||
| + | |||
| + | Now, let's compare the Cortex-M and Cortex-A series. The ARMv8-A processor series supports three instruction | ||
| + | ARM Cortex-M processors based on ARMv7 can execute two instruction sets: Thumb and ARM. The Thumb instructions are 16-bit wide and have some restrictions, | ||
| + | |||
| + | Looking at the ARMv8-A processors, the instruction sets make a difference. AArch32 execution state can execute programs designed for ARMv7 processors. This means many A32 or T32 instructions on ARMv8 are identical to the ARMv7 ARM or THUMB instructions, respectively. On ARMv7 processors, the THUMB instruction set has some restrictions, | ||
| + | Let's look at the machine code generated by the assembler to determine why the exact instruction set imposes restrictions on the ARMv8 processor. We will take just one instruction, | ||
| + | |||
| + | **A64** | ||
| + | |||
| + | The machine code for the MOV instruction is given in the figure above. The bit values presented are fixed for proper identification of the operation. The ‘sf’ bit identifies data encoding variant 32-bit (sf=0) or 64-bit(sf=1). The ‘sf’ bit does not change the instruction binary code. | ||
| + | |||
| + | {{: | ||
| + | |||
| + | The ‘Rm’ and the ‘Rd’ bit fields | ||
| + | |||
| + | **A32** | ||
| + | |||
| + | The figure above shows the same instruction, | ||
| + | |||
| + | {{: | ||
| + | |||
| + | |||
| + | Other bitfields, like ‘cond’, are also used for conditional instruction execution. The ‘S’ bit identifies whether | ||
| + | |||
| + | <table tab_label> | ||
| + | < | ||
| + | ^ ‘stype’ | ||
| + | |0b00 |LSL |Logical Shift Left | | ||
| + | |0b01 |LSR |Logical Shift Right | | ||
| + | |0b10 |ASR |Arithmetic Shift Right | | ||
| + | |0b11 |ROR |ROtate Right | | ||
| + | </ | ||
| + | |||
| + | Many instructions include options such as bit shifting. These operations also have specific instructions for binary bit shifting. These shifts affect the operand values. Shifting the register left or right by one bit multiplies or divides the value by 2, respectively. | ||
| + | |||
| + | {{ : | ||
| + | {{ : | ||
| + | {{ : | ||
| + | {{ : | ||
| + | {{ : | ||
| + | |||
| + | **T32** | ||
| + | |||
| + | The Thumb instructions have multiple machine codes for this one operation. | ||
| + | |||
| + | {{: | ||
| + | |||
| + | T1 THUMB instruction D bit and Rd fields together identify the destination register. The source and destination registers can now be addressed with only 4 bits, so only 16 general-purpose registers are accessible. A smaller number of registers can be accessed | ||
| + | |||
| + | {{: | ||
| + | |||
| + | The OP bitfield specifies the shift type, and imm5 specifies the amount. The result Rd will be shifted by imm5 bits from the Rm register. | ||
| + | Finally, the last machine code for this instruction is a sixteen 16-bit-wide instruction, | ||
| + | |||
| + | {{: | ||
| + | |||
| + | Different machine codes for the T32 instructions allow you to choose the most suitable one, but the code must be consistent with a single machine code type. Switching between machine code types in the processor is still possible, but compiling code that uses multiple machine codes will be even more complicated than learning assembler. | ||
| + | |||
| + | Summarising these instruction sets, the A32 was best suited to ARMv7 processors, with only 16 general-purpose registers. For ARMv8, there are 31 registers to address, forcing ARM to introduce the A64 instruction set, which supports 32 registers. This is why all code examples in the following sections are created using the A64 instruction set. | ||
| + | |||