I want to know in the following simple code, at which point the variable c
is being calculated. Does it get calculated before main
label? Or when execution in main reaches the ldr r0, [r3]
instruction, it will call the _GLOBAL__sub_I_a
function/label?
Basically how to read the assembly code in this case (it is ARM none). The code can be found here: https://godbolt.org/z/jcYahM1zW
c++:
#include <cstdio>
int a = 2;
int b = 5;
int c = a * b;
int main() {
return c;
}
Assembly:
main:
ldr r3, .L3
ldr r0, [r3]
bx lr
.L3:
.word .LANCHOR0
_GLOBAL__sub_I_a:
ldr r2, .L6
ldr r3, [r2]
ldr r2, [r2, #4]
mul r3, r2, r3
ldr r1, .L6+4
str r3, [r1]
bx lr
.L6:
.word .LANCHOR1
.word .LANCHOR0
a:
.word 2
b:
.word 5
c: