Alert: no free registers Question
Posted: Thu May 16, 2024 2:09 am
The following test code is distilled from a real use case. This is with Astrobe for Cortex-M0 v9.2.
Compiling gives a 'no free registers' Alert for the call of 'p0'.
The cause of the Alert is evident in the assembly listing:
I think I understand the need for this method of loading a byte-sized argument from the stack: no encoding T2 for 'ldrb', as we have for 'ldr', eg. 'ldr r1,[sp,#4]'. Here we're "unlucky" that the byte-sized parameter is the last one.
Rearranging the parameters as in procedure 'p1' avoids the issue, but I wonder if the compiler could generate this code:
I am aware this is an edge case, with eight parameters, and the last one byte-sized. Or even more on the edge, eight byte-sized parameters, where rearranging could not resolve the situation.
PS: the new Alert system is really useful, allowing to inspect the assembly code in cases like this.
Code: Select all
MODULE M;
VAR v0: INTEGER;
PROCEDURE p0(i0, i1, i2, i3, i4, i5: INTEGER; i6: INTEGER; b7: BOOLEAN); END p0;
PROCEDURE p1(i0, i1, i2, i3, i4, i5: INTEGER; b6: BOOLEAN; i7: INTEGER); END p1;
PROCEDURE p2;
VAR v1: INTEGER; b1: BOOLEAN;
BEGIN
p0(v0, v1, 0, 1, 2, 3, 4, b1);
p1(v0, v1, 0, 1, 2, 3, b1, 4);
END p2;
END M.
The cause of the Alert is evident in the assembly listing:
Code: Select all
p0(v0, v1, 0, 1, 2, 3, 4, b1);
. 24 018H 0480EH ldr r0,[pc,#56] -> 84
. 26 01AH 06800H ldr r0,[r0]
. 28 01CH 09900H ldr r1,[sp]
. 30 01EH 02200H movs r2,#0
. 32 020H 02301H movs r3,#1
. 34 022H 02402H movs r4,#2
. 36 024H 02503H movs r5,#3
. 38 026H 02604H movs r6,#4
. 40 028H 0A801H add r0,sp,#4 <===
. 42 02AH 07807H ldrb r7,[r0]
Rearranging the parameters as in procedure 'p1' avoids the issue, but I wonder if the compiler could generate this code:
Code: Select all
p0(v0, v1, 0, 1, 2, 3, 4, b1);
. 24 018H 0480EH ldr r0,[pc,#56] -> 84
. 26 01AH 06800H ldr r0,[r0]
. 28 01CH 09900H ldr r1,[sp]
. 30 01EH 02200H movs r2,#0
. 32 020H 02301H movs r3,#1
. 34 022H 02402H movs r4,#2
. 36 024H 02503H movs r5,#3
. 38 026H 02604H movs r6,#4
. 40 028H 0AF01H add r7,sp,#4
. 42 02AH 0783FH ldrb r7,[r7]
PS: the new Alert system is really useful, allowing to inspect the assembly code in cases like this.