编程语言
首页 > 编程语言> > [ARM-assembly]-C语言和汇编对比学习

[ARM-assembly]-C语言和汇编对比学习

作者:互联网

(1)

static int x;
//static int y = 10;
//int z;
//int w = 20;

int main()
{
        int s = 200;

        x = 100;
        s=s+x;

//      s=s+y;

//      z=100;
//      s=s+z;

//      s=s+w;

        return 0;
}
hehezhou@buildsrv-165:~/workspace/test/test1$ aarch64-linux-android-objdump -D main.o

main.o:     file format elf64-littleaarch64


Disassembly of section .text:

0000000000000000 <main>:
   0:   d10043ff        sub     sp, sp, #0x10
   4:   52801900        mov     w0, #0xc8                       // #200
   8:   b9000fe0        str     w0, [sp,#12]
   c:   90000000        adrp    x0, 0 <main>
  10:   91000000        add     x0, x0, #0x0
  14:   52800c81        mov     w1, #0x64                       // #100
  18:   b9000001        str     w1, [x0]
  1c:   90000000        adrp    x0, 0 <main>
  20:   91000000        add     x0, x0, #0x0
  24:   b9400000        ldr     w0, [x0]
  28:   b9400fe1        ldr     w1, [sp,#12]
  2c:   0b000020        add     w0, w1, w0
  30:   b9000fe0        str     w0, [sp,#12]
  34:   52800000        mov     w0, #0x0                        // #0
  38:   910043ff        add     sp, sp, #0x10
  3c:   d65f03c0        ret

Disassembly of section .bss:

0000000000000000 <x>:
   0:   00000000        .word   0x00000000

Disassembly of section .comment:

0000000000000000 <.comment>:
   0:   43434700        .inst   0x43434700 ; undefined
   4:   4728203a        .inst   0x4728203a ; undefined
   8:   2029554e        .inst   0x2029554e ; undefined
   c:   2e392e34        uqsub   v20.8b, v17.8b, v25.8b
  10:   30322078        adr     x24, 6441d <main+0x6441d>
  14:   31303531        adds    w17, w9, #0xc0d
  18:   28203332        stnp    w18, w12, [x25,#-256]
  1c:   72657270        .inst   0x72657270 ; undefined
  20:   61656c65        .inst   0x61656c65 ; undefined
  24:   00296573        .inst   0x00296573 ; NYI

(2)

//static int x;
static int y = 10;
//int z;
//int w = 20;

int main()
{
        int s = 200;

//      x = 100;
//      s=s+x;

        s=s+y;

//      z=100;
//      s=s+z;

//      s=s+w;

        return 0;
}
hehezhou@buildsrv-165:~/workspace/test/test1$ aarch64-linux-android-objdump -D main.o

main.o:     file format elf64-littleaarch64


Disassembly of section .text:

0000000000000000 <main>:
   0:   d10043ff        sub     sp, sp, #0x10
   4:   52801900        mov     w0, #0xc8                       // #200
   8:   b9000fe0        str     w0, [sp,#12]
   c:   90000000        adrp    x0, 0 <main>
  10:   91000000        add     x0, x0, #0x0
  14:   b9400000        ldr     w0, [x0]
  18:   b9400fe1        ldr     w1, [sp,#12]
  1c:   0b000020        add     w0, w1, w0
  20:   b9000fe0        str     w0, [sp,#12]
  24:   52800000        mov     w0, #0x0                        // #0
  28:   910043ff        add     sp, sp, #0x10
  2c:   d65f03c0        ret

Disassembly of section .data:

0000000000000000 <y>:
   0:   0000000a        .word   0x0000000a

Disassembly of section .comment:

0000000000000000 <.comment>:
   0:   43434700        .inst   0x43434700 ; undefined
   4:   4728203a        .inst   0x4728203a ; undefined
   8:   2029554e        .inst   0x2029554e ; undefined
   c:   2e392e34        uqsub   v20.8b, v17.8b, v25.8b
  10:   30322078        adr     x24, 6441d <main+0x6441d>
  14:   31303531        adds    w17, w9, #0xc0d
  18:   28203332        stnp    w18, w12, [x25,#-256]
  1c:   72657270        .inst   0x72657270 ; undefined
  20:   61656c65        .inst   0x61656c65 ; undefined
  24:   00296573        .inst   0x00296573 ; NYI

(3)、

//static int x;
//static int y = 10;
int z;
//int w = 20;

int main()
{
        int s = 200;

//      x = 100;
//      s=s+x;

//      s=s+y;

        z=100;
        s=s+z;

//      s=s+w;

        return 0;
}
hehezhou@buildsrv-165:~/workspace/test/test1$ aarch64-linux-android-objdump -D main.o

main.o:     file format elf64-littleaarch64


Disassembly of section .text:

0000000000000000 <main>:
   0:   d10043ff        sub     sp, sp, #0x10
   4:   52801900        mov     w0, #0xc8                       // #200
   8:   b9000fe0        str     w0, [sp,#12]
   c:   90000000        adrp    x0, 4 <main+0x4>
  10:   f9400000        ldr     x0, [x0]
  14:   52800c81        mov     w1, #0x64                       // #100
  18:   b9000001        str     w1, [x0]
  1c:   90000000        adrp    x0, 4 <main+0x4>
  20:   f9400000        ldr     x0, [x0]
  24:   b9400000        ldr     w0, [x0]
  28:   b9400fe1        ldr     w1, [sp,#12]
  2c:   0b000020        add     w0, w1, w0
  30:   b9000fe0        str     w0, [sp,#12]
  34:   52800000        mov     w0, #0x0                        // #0
  38:   910043ff        add     sp, sp, #0x10
  3c:   d65f03c0        ret

Disassembly of section .comment:

0000000000000000 <.comment>:
   0:   43434700        .inst   0x43434700 ; undefined
   4:   4728203a        .inst   0x4728203a ; undefined
   8:   2029554e        .inst   0x2029554e ; undefined
   c:   2e392e34        uqsub   v20.8b, v17.8b, v25.8b
  10:   30322078        adr     x24, 6441d <main+0x6441d>
  14:   31303531        adds    w17, w9, #0xc0d
  18:   28203332        stnp    w18, w12, [x25,#-256]
  1c:   72657270        .inst   0x72657270 ; undefined
  20:   61656c65        .inst   0x61656c65 ; undefined
  24:   00296573        .inst   0x00296573 ; NYI

(4)、

//static int x;
//static int y = 10;
//int z;
int w = 20;

int main()
{
        int s = 200;

//      x = 100;
//      s=s+x;

//      s=s+y;

//      z=100;
//      s=s+z;

        s=s+w;

        return 0;
}
hehezhou@buildsrv-165:~/workspace/test/test1$ aarch64-linux-android-gcc-4.9 -c main.c
Android GCC has been deprecated in favor of Clang, and will be removed from
Android in 2020-01 as per the deprecation plan in:
https://android.googlesource.com/platform/prebuilts/clang/host/linux-x86/+/master/GCC_4_9_DEPRECATION.md


hehezhou@buildsrv-165:~/workspace/test/test1$ aarch64-linux-android-objdump -D main.o

main.o:     file format elf64-littleaarch64


Disassembly of section .text:

0000000000000000 <main>:
   0:   d10043ff        sub     sp, sp, #0x10
   4:   52801900        mov     w0, #0xc8                       // #200
   8:   b9000fe0        str     w0, [sp,#12]
   c:   90000000        adrp    x0, 0 <main>
  10:   f9400000        ldr     x0, [x0]
  14:   b9400000        ldr     w0, [x0]
  18:   b9400fe1        ldr     w1, [sp,#12]
  1c:   0b000020        add     w0, w1, w0
  20:   b9000fe0        str     w0, [sp,#12]
  24:   52800000        mov     w0, #0x0                        // #0
  28:   910043ff        add     sp, sp, #0x10
  2c:   d65f03c0        ret

Disassembly of section .data:

0000000000000000 <w>:
   0:   00000014        .word   0x00000014

Disassembly of section .comment:

0000000000000000 <.comment>:
   0:   43434700        .inst   0x43434700 ; undefined
   4:   4728203a        .inst   0x4728203a ; undefined
   8:   2029554e        .inst   0x2029554e ; undefined
   c:   2e392e34        uqsub   v20.8b, v17.8b, v25.8b
  10:   30322078        adr     x24, 6441d <main+0x6441d>
  14:   31303531        adds    w17, w9, #0xc0d
  18:   28203332        stnp    w18, w12, [x25,#-256]
  1c:   72657270        .inst   0x72657270 ; undefined
  20:   61656c65        .inst   0x61656c65 ; undefined
  24:   00296573        .inst   0x00296573 ; NYI

(5)

static int x;
static int y = 10;
int z;
int w = 20;

int main()
{
        int s = 200;

        x = 100;
        s=s+x;

        s=s+y;

        z=100;
        s=s+z;

        s=s+w;

        return 0;
}
hehezhou@buildsrv-165:~/workspace/test/test1$ aarch64-linux-android-objdump -D main.o

main.o:     file format elf64-littleaarch64


Disassembly of section .text:

0000000000000000 <main>:
   0:   d10043ff        sub     sp, sp, #0x10
   4:   52801900        mov     w0, #0xc8                       // #200
   8:   b9000fe0        str     w0, [sp,#12]
   c:   90000000        adrp    x0, 0 <main>
  10:   91000000        add     x0, x0, #0x0
  14:   52800c81        mov     w1, #0x64                       // #100
  18:   b9000001        str     w1, [x0]
  1c:   90000000        adrp    x0, 0 <main>
  20:   91000000        add     x0, x0, #0x0
  24:   b9400000        ldr     w0, [x0]
  28:   b9400fe1        ldr     w1, [sp,#12]
  2c:   0b000020        add     w0, w1, w0
  30:   b9000fe0        str     w0, [sp,#12]
  34:   90000000        adrp    x0, 0 <main>
  38:   91000000        add     x0, x0, #0x0
  3c:   b9400000        ldr     w0, [x0]
  40:   b9400fe1        ldr     w1, [sp,#12]
  44:   0b000020        add     w0, w1, w0
  48:   b9000fe0        str     w0, [sp,#12]
  4c:   90000000        adrp    x0, 4 <main+0x4>
  50:   f9400000        ldr     x0, [x0]
  54:   52800c81        mov     w1, #0x64                       // #100
  58:   b9000001        str     w1, [x0]
  5c:   90000000        adrp    x0, 4 <main+0x4>
  60:   f9400000        ldr     x0, [x0]
  64:   b9400000        ldr     w0, [x0]
  68:   b9400fe1        ldr     w1, [sp,#12]
  6c:   0b000020        add     w0, w1, w0
  70:   b9000fe0        str     w0, [sp,#12]
  74:   90000000        adrp    x0, 4 <main+0x4>
  78:   f9400000        ldr     x0, [x0]
  7c:   b9400000        ldr     w0, [x0]
  80:   b9400fe1        ldr     w1, [sp,#12]
  84:   0b000020        add     w0, w1, w0
  88:   b9000fe0        str     w0, [sp,#12]
  8c:   52800000        mov     w0, #0x0                        // #0
  90:   910043ff        add     sp, sp, #0x10
  94:   d65f03c0        ret

Disassembly of section .data:

0000000000000000 <y>:
   0:   0000000a        .word   0x0000000a

0000000000000004 <w>:
   4:   00000014        .word   0x00000014

Disassembly of section .bss:

0000000000000000 <x>:
   0:   00000000        .word   0x00000000

Disassembly of section .comment:

0000000000000000 <.comment>:
   0:   43434700        .inst   0x43434700 ; undefined
   4:   4728203a        .inst   0x4728203a ; undefined
   8:   2029554e        .inst   0x2029554e ; undefined
   c:   2e392e34        uqsub   v20.8b, v17.8b, v25.8b
  10:   30322078        adr     x24, 6441d <w+0x64419>
  14:   31303531        adds    w17, w9, #0xc0d
  18:   28203332        stnp    w18, w12, [x25,#-256]
  1c:   72657270        .inst   0x72657270 ; undefined
  20:   61656c65        .inst   0x61656c65 ; undefined
  24:   00296573        .inst   0x00296573 ; NYI

标签:assembly,undefined,int,sp,C语言,inst,w0,x0,ARM
来源: https://blog.51cto.com/u_15278218/2930976