This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| en:multiasm:paarm:chapter_5_2 [2024/09/27 20:24] – created pczekalski | 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 ====== | ||
| + | |||
| + | 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 to read the manual and syntax for each software used to create the code and compile it. | ||
| + | |||
| + | Now, let's compare the Cortex-M and Cortex-A series. The ARMv8-A processor series supports three instruction sets: A32, T32, and A64. A32 and T32 are the Arm and Thumb instruction sets, respectively. These instruction sets are used to execute instructions in the AArch32 Execution state. The A64 instruction set is used when executing in the AArch64 Execution state, and there are no 64-bit-wide instructions; | ||
| + | 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, | ||
| + | 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 identify the exact register number from which the data will be copied to the destination register. Each is 5 bits wide, so all 32 CPU registers can be addressed. The ‘sf’ bit only identifies the number of bits to be copied between registers: 32 or 64 bits of data. The ‘opc’ bitfield identifies the operation variant (addressing mode for this instruction), | ||
| + | |||
| + | **A32** | ||
| + | |||
| + | The figure above shows the same instruction, | ||
| + | |||
| + | {{: | ||
| + | |||
| + | |||
| + | Other bitfields, like ‘cond’, are also used for conditional instruction execution. The ‘S’ bit identifies whether the status register must be updated. The ’stype’ bitfield is used for the type of shift to be applied to the second source register, and finally, the ‘imm5’ bitfield is used to identify the shift amount 0 to 31. | ||
| + | |||
| + | <table tab_label> | ||
| + | < | ||
| + | ^ ‘stype’ bit-field value ^ Shift type ^ Meaning ^ | ||
| + | |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 in the following machine code. | ||
| + | |||
| + | {{: | ||
| + | |||
| + | 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. Notice that only three bits are used to address the general-purpose registers – only eight registers are accessible. | ||
| + | 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. | ||
| + | |||
| + | |||