0%

读懂汇编代码之hello World

前言:今天学习汇编代码

汇编语言及注释

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
	.file	"\261\340\322\353\324\255\300\355.c"  ;指定文件名
.intel_syntax noprefix ;使用intel风格的汇编代码
.def ___main; .scl 2; .type 32; .endef ;(.def):定义一个全局符号
.section .rdata,"dr" ;指定一个包含只读数据的段
LC0: ;定义一个字符串常量"hello world",以空字符(\0)结尾
.ascii "hello world\0"
.text ;指定一个包含可执行代码的段
.globl _main ;声明_main函数为全局可见
.def _main; .scl 2; .type 32; .endef
_main: ;(_main)程序的入口点,开始执行代码
LFB10:
.cfi_startproc
push ebp ;建立堆栈帧
.cfi_def_cfa_offset 8
.cfi_offset 5, -8
mov ebp, esp ;建立堆栈帧
.cfi_def_cfa_register 5
and esp, -16 ;将栈指针对齐到16字节边界
sub esp, 16 ;将栈指针对齐到16字节边界
call ___main ;调用main函数(在这里时C运行时库的起始化)
mov DWORD PTR [esp], OFFSET FLAT:LC0 ;将字符串常量LC0的地址压入栈
call _puts ;调用puts函数,将字符串打印到标准输出
mov eax, 0 ;将返回值设为0
leave ;恢复堆栈帧
.cfi_restore 5
.cfi_def_cfa 4, 4
ret ;返回
.cfi_endproc
LFE10:
.ident "GCC: (MinGW.org GCC-6.3.0-1) 6.3.0" ;表面使用的gcc版本
.def _puts; .scl 2; .type 32; .endef