2019-2020-1 20199312 "Linux kernel principle and Analysis" in the second week of work

c language code


// main.c
int g(int x)
{
    return x + 4;
}

int f(int x)
{
    return g(x);
}

int main(void)
{
    return f(6) + 2;
}

Decompile assembly code

    .file   "main.c"
    .text
    .globl  g
    .type   g, @function
g:
.LFB0:
    .cfi_startproc
    pushl   %ebp
    .cfi_def_cfa_offset 8
    .cfi_offset 5, -8
    movl    %esp, %ebp
    .cfi_def_cfa_register 5
    movl    8(%ebp), %eax
    addl    $4, %eax
    popl    %ebp
    .cfi_restore 5
    .cfi_def_cfa 4, 4
    ret
    .cfi_endproc
.LFE0:
    .size   g, .-g
    .globl  f
    .type   f, @function
f:
.LFB1:
    .cfi_startproc
    pushl   %ebp
    .cfi_def_cfa_offset 8
    .cfi_offset 5, -8
    movl    %esp, %ebp
    .cfi_def_cfa_register 5
    subl    $4, %esp
    movl    8(%ebp), %eax
    movl    %eax, (%esp)
    call    g
    leave
    .cfi_restore 5
    .cfi_def_cfa 4, 4
    ret
    .cfi_endproc
.LFE1:
    .size   f, .-f
    .globl  main
    .type   main, @function
main:
.LFB2:
    .cfi_startproc
    pushl   %ebp
    .cfi_def_cfa_offset 8
    .cfi_offset 5, -8
    movl    %esp, %ebp
    .cfi_def_cfa_register 5
    subl    $4, %esp
    movl    $6, (%esp)
    call    f
    addl    $2, %eax
    leave
    .cfi_restore 5
    .cfi_def_cfa 4, 4
    ret
    .cfi_endproc
.LFE2:
    .size   main, .-main
    .ident  "GCC: (Ubuntu 4.8.2-19ubuntu1) 4.8.2"
    .section    .note.GNU-stack,"",@progbits

Code highlighting language keywords corresponding
language name keyword
C ++ cpp
C # cs
CSS CSS
the Java the Java
JavaScript JavaScript
JSON json
Markdown Markdown
Python Python
SQL SQL
XML xml
x86 assembler x86asm

Registers
General-purpose registers:

AX: Accumulator BX: base address register CX: count register DX: data register BP: base address stack needle SI, DI: index register
SP: Stack Top Pointer

Segment registers:

CS: Code segment register points to the segment containing program instructions. SS: stack segment register points to the segment containing the current program stack. DS: data segment register points to a static data or a global data segment.
ES: additional registers, additional data points to segment

Addressing

movl% eax,% edx edx = eax register addressing
movl $ 0x123,% edx edx = 0x123 immediate addressing
movl $ 0x123,% edx edx = * (int32_t) 0x123 direct addressing
movl (% ebx),% edx edx = (int32_t) ebx indirect addressing
movl 4 (% ebx),% edx edx = (int32_t) (ebx + 4) indexed addressing

Guess you like

Origin www.cnblogs.com/banpingcu/p/11564790.html