罗列的博客

这是一个罗列发呆的地方

0%

gcc使用

gcc

1
2
3
4
5
6
7
8
9
10
11
12
13
[text] C program (p1.c p2.c)
|
| [Compiler] (gcc -Og -S)
V
[text] Asm program (p1.s p2.s)
|
| [Assembler] (gcc / as)
V
[binary] Object program (p1.o p2.o)
|
| [Linker] (gcc / ld)
V {add static libraries .a}
[binary] Executable program (p)
1
2
-S : generate asm file .s (or will generate .out)
-Og: basic optimization

just like this

1
2
3
4
5
6
7
8
// sum.c
long plus(long x, long y);

void sumstore(long x, long y, long *dest)
{
long t = plus(x, y);
*dest = t;
}
1
2
3
4
5
6
7
<!-- sum.s -->
pushq %rbx
movq %rdx, %rbx
call plus@PLT
movq %rax, (%rbx)
popq %rbx
ret

disassemble

1
objdump -d sum.o > sum.d

output to sum.d

reg

1
2
3
4
5
parm1: %rdi
parm2: %rsi
parm3: %rdx

ret: %rax

instruction

1
movzbl: move with zero extension byte to long

for x86-64:
any computation where the result is a 32-bit result. it will add zero to the remaining 32 bits of the register (other just like 16-bit or 8-bit will not)

call func & local variable

caller saved and callee saved

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
%rax: return value

%rdi
%rsi
%rdx
%rcx
%r8
%r9: 6 reg used to passing arguments

%r10
%r11: caller saved temporaries

%rbx
%r12
%r13
%r14: callee must save

%rbp: callee saved used as frame ptr

%rsp: callee save, restored to original value on exit from procedure