whartung wrote:
8BIT wrote:
(I don't know if you can compile the C code with the source code as comments to the assembly or not).
That should in principle be easy with gcc: gcc -fverbose-asm -S source.c
That works fine on Intel. But not with the arm version of gcc on my pi3, for some reason. But you can match source lines to code with objdump if you compile with the -g flag and then use objdump on the .o file:
Code:
$ cat pr.c
int test (int a)
{
int b;
int c;
b = a + 2;
c = b + 3;
return (c);
}
$ gcc -c -g pr.c
$ objdump -d -S pr.o
pr.o: file format elf32-littlearm
Disassembly of section .text:
00000000 <test>:
int test (int a)
{
0: e52db004 push {fp} ; (str fp, [sp, #-4]!)
4: e28db000 add fp, sp, #0
8: e24dd014 sub sp, sp, #20
c: e50b0010 str r0, [fp, #-16]
int b;
int c;
b = a + 2;
10: e51b3010 ldr r3, [fp, #-16]
14: e2833002 add r3, r3, #2
18: e50b3008 str r3, [fp, #-8]
c = b + 3;
1c: e51b3008 ldr r3, [fp, #-8]
20: e2833003 add r3, r3, #3
24: e50b300c str r3, [fp, #-12]
return (c);
28: e51b300c ldr r3, [fp, #-12]
}
2c: e1a00003 mov r0, r3
30: e24bd000 sub sp, fp, #0
34: e49db004 pop {fp} ; (ldr fp, [sp], #4)
38: e12fff1e bx lr
pi@