I am involved with safety critical software development to RTCA/DO-178C Level A.
Compiler:
ti-cgt-arm_18.1.4.LTS
Options:
-mv7R4
--code_state=32
-Ooff
--opt_for_speed=0
--c99
Consider the following C source code:
#define TRUE 1
#define FALSE 0
typedef unsigned char BOOL;
static BOOL Test_A (const BOOL ParamA);
int main(void) {
(void) Test_A(TRUE);
return (0);
}
static BOOL Test_A (const BOOL ParamA)
{
BOOL Result = !ParamA;
return (Result);
}
The disassembly for the line of source code which uses the logical negation operator is as follows:
21 BOOL Result = !ParamA;
00002894: E5DD1000 ldrb r1, [r13]
00002898: E3A0C000 mov r12, #0
0000289c: E3510000 cmp r1, #0
000028a0: E3A00000 mov r0, #0
000028a4: 0A000000 beq $C$L1
000028a8: E3A00001 mov r0, #1
$C$L1:
000028ac: E3500000 cmp r0, #0
000028b0: 1A000000 bne $C$L2
000028b4: E3A0C001 mov r12, #1
$C$L2:
000028b8: E5CDC001 strb r12, [r13, #1]
Even though optimisation is off (-Ooff), the implementation above seems unnecessarily complex, in particular the use of register r0.
Question:
Is there a legitimate reason as to why the implementation uses an 'additional' register (r0) and two labels rather than a single label implementation such as that detailed in the example below?
00002894: E5DD0000 ldrb r0, [r13]
00002898: E3A0C001 mov r12, #1
0000289c: E3500000 cmp r0, #0
000028a0: 0A000000 beq $C$L1
000028a4: E3A0C000 mov r12, #0
$C$L1:
000028a8: E5CDC001 strb r12, [r13, #1]