marcelru wrote:why not do
gcc -S -o filename.s filename.c?
Saves a disassembly run.
Thank you marcelr for your 2ct. Thanks to your idea, I quote two versions of compiled button_pressed() function, with my comments.
First,
working version:
Code: Select all
.align 2
.type button_pressed, %function
button_pressed: <-------------- function entry point
@ args = 0, pretend = 0, frame = 0
@ frame_needed = 0, uses_anonymous_args = 0
@ link register save eliminated.
cmp r0, #15 <-------------- if (r0_key != KEY_MUTE)...
movne r2, r0 <-------------- ...r2_key = 0;
moveq r2, #255 <-------------- ...else r2_key = KEY_NOTHING;
ldr r3, .L5 <-------------- r3_unused = unused;
mov r0, r2 <-------------- r0_key = r2_key;
@ lr needed for prologue
str r2, [r3, #0] <-------------- unused = r3_unused;
bx lr <-------------- return; // while r0 register still contains new 'key' value
.L6:
.align 2
.L5:
.word unused <-------------- int unused;
.size button_pressed, .-button_pressed
Next,
hanging version, with extra operations on "unused" integer removed:
Code: Select all
.align 2
.type button_pressed, %function
button_pressed: <-------------- function entry point
@ args = 0, pretend = 0, frame = 0
@ frame_needed = 0, uses_anonymous_args = 0
@ link register save eliminated.
cmp r0, #15 <-------------- if (r0_key == KEY_MUTE)...
moveq r0, #255 <-------------- r0_key = KEY_NOTHING; // else r0_key stays untouched
@ lr needed for prologue
bx lr <-------------- return; // while r0 register still contains new 'key' value
.size button_pressed, .-button_pressed
Well, I can see no errors in the listings above. But the differences begin to come out in
injection_press() function:
Again, a piece of working code:
Code: Select all
...
injection_press:
@ args = 0, pretend = 0, frame = 0
@ frame_needed = 0, uses_anonymous_args = 0
str lr, [sp, #-4]!
sub sp, sp, #4
#APP
STMFD SP!, {R0,R2,R3,R12}
mov r0, r1 <------------- // set input argument (key)
bl button_pressed <------------- // call button_pressed() function
#APP
MOV R1, R0
...
And "bad" code:
Code: Select all
...
injection_press:
@ args = 0, pretend = 0, frame = 0
@ frame_needed = 0, uses_anonymous_args = 0
@ link register save eliminated.
@ lr needed for prologue
#APP
STMFD SP!, {R0,R2,R3,R12}
<-------------- where it is ?????????????
MOV R1, R0
...
As you can see,
calling of button_pressed() function disappeared.
@sbav1: I still don't understand how gcc could treat this function as a null one. Function looks like very "classic": it gets a value, processes that value and returns other value. I cannot see the reason to remove it since it is even called within another function, so it is used. Even R0 register returned in asm point of view, also is used later.
Maybe I will never understand this case, but please don't worry about me. Of course, it is always better to understand how code works - that's why I asked you for help. Anyways, I will try to re-design my code to get rid of this problem. Thanks for your suggestions.