Examples
The following example demonstrates the effect of the
-ffixed-rN
option.
Source file bar.c
contains the following code:
int bar(unsigned int i, unsigned int j,
unsigned int k, unsigned int l,
unsigned int m, unsigned int n,
unsigned int o, unsigned int p,
unsigned int q, unsigned int r,
unsigned int s)
{
return (i + j + k + l + m + n + o + p + q + r + s);
}
Compile this code without any -ffixed-rN
option:
armclang --target=arm-arm-none-eabi -march=armv8-a -O0 -S bar.c -o bar.s
The generated assembly file, bar.s
, saves the registers that it needs to use, which are {r4, r5, r6, r7, r8, lr}
:
bar:
.fnstart
.cfi_sections .debug_frame
.cfi_startproc
@ %bb.0:
.save {r4, r5, r6, r7, r8, lr}
push {r4, r5, r6, r7, r8, lr}
.cfi_def_cfa_offset 24
.cfi_offset lr, -4
.cfi_offset r8, -8
.cfi_offset r7, -12
.cfi_offset r6, -16
.cfi_offset r5, -20
.cfi_offset r4, -24
.pad #16
sub sp, sp, #16
/* Code in between is hidden */
add sp, sp, #16
pop {r4, r5, r6, r7, r8, pc}
.Lfunc_end0:
To ensure that the compiler does not use registers R6, R7, and R8, compile the same code in foo.c
with the -ffixed-r6
, -ffixed-r7
, and -ffixed-r8
options:
armclang --target=arm-arm-none-eabi -march=armv8-a -O0 -ffixed-r6 -ffixed-r7 -ffixed-r8 -S bar.c -o bar.s
The generated assembly file, bar.s
, saves the registers that it needs to use, which are {r4, r5, r9, r10, r11, lr}
. In this bar.s
, the compiler uses registers R9, R10, and R11 instead of R6, R7, and R8:
bar:
.fnstart
.cfi_sections .debug_frame
.cfi_startproc
@ %bb.0:
.save {r4, r5, r9, r10, r11, lr}
push {r4, r5, r9, r10, r11, lr}
.cfi_def_cfa_offset 24
.cfi_offset lr, -4
.cfi_offset r11, -8
.cfi_offset r10, -12
.cfi_offset r9, -16
.cfi_offset r5, -20
.cfi_offset r4, -24
.pad #16
sub sp, sp, #16
/* Code in between is hidden */
add sp, sp, #16
pop {r4, r5, r9, r10, r11, pc}
.Lfunc_end0: