- 论坛徽章:
- 1
|
本帖最后由 goingstudy 于 2015-06-03 16:38 编辑
这是C 代码:- #include <stdio.h>
- int main()
- {
- char str[16]= "";
- if ( str[0] != '\0')
- printf("1\n");
- else
- printf("2\n");
- return 0;
- }
复制代码 gcc -S 对应的汇编:- .file "1.c"
- .section .rodata
- .LC1:
- .string "1"
- .LC2:
- .string "2"
- .LC0:
- .string ""
- .zero 15
- .text
- .globl main
- .type main, @function
- main:
- .LFB2:
- pushq %rbp
- .LCFI0:
- movq %rsp, %rbp
- .LCFI1:
- subq $16, %rsp
- .LCFI2:
- movzbl .LC0(%rip), %eax ;这个是取.LC0处的一个字符放到eax中吗?
- movb %al, -16(%rbp) ;然后放到str[]数组的第1个元素
- movq $0, -15(%rbp) ;0->str的第2-9个元素
- movl $0, -7(%rbp) ;0->str的第10-13个元素
- movw $0, -3(%rbp) ;0->str的第14-15个元素
- movb $0, -1(%rbp) ;0->str的第16个元素
- movzbl -16(%rbp), %eax ;取str的第一个元素到eax中
- testb %al, %al ;这个地方为什么这么测试?
- je .L2
- movl $.LC1, %edi
- call puts
- jmp .L4
- .L2:
- movl $.LC2, %edi
- call puts
- .L4:
- movl $0, %eax
- leave
- ret
- .LFE2:
- .size main, .-main
- .section .eh_frame,"a",@progbits
- .Lframe1:
- .long .LECIE1-.LSCIE1
- .LSCIE1:
- .long 0x0
- .byte 0x1
- .string "zR"
- .uleb128 0x1
- .sleb128 -8
- .byte 0x10
- .uleb128 0x1
- .byte 0x3
- .byte 0xc
- .uleb128 0x7
- .uleb128 0x8
- .byte 0x90
- .uleb128 0x1
- .align 8
- .LECIE1:
- .LSFDE1:
- .long .LEFDE1-.LASFDE1
- .LASFDE1:
- .long .LASFDE1-.Lframe1
- .long .LFB2
- .long .LFE2-.LFB2
- .uleb128 0x0
- .byte 0x4
- .long .LCFI0-.LFB2
- .byte 0xe
- .uleb128 0x10
- .byte 0x86
- .uleb128 0x2
- .byte 0x4
- .long .LCFI1-.LCFI0
- .byte 0xd
- .uleb128 0x6
- .align 8
- .LEFDE1:
- .ident "GCC: (GNU) 4.1.2 20071124 (Red Hat 4.1.2-42)"
- .section .note.GNU-stack,"",@progbits
复制代码 我上面的那段注释理解的正确吗? |
|