![]() |
#2
zklhp2012-09-01 15:19
|
和我印象里学汇编的时间出入不大。我应该是 09 年暑假开始学的,看的书讲的是 masm。在 windows 下实践半年,学的差不多了才开始转战 linux,好像是比较合逻辑的。
其实就是 hello word 而已。还有详细的注释,应该是怕日后自己也看不懂。AT&T 语法的,但其实和 intel 语法区别也不是很大。
比如 mov a, b 的意思是 move a to b,和正常说话的语序是一样的。寄存器的名字前要加 %, 变量或立即数前要加 $。
不过看了看,感觉我现在能写的最复杂的汇编也许也就这个程度。

.data # section declaration
msg:
.ascii "Hello, world!\n"
len = . - msg # length of string
.text # section declaration
# we must export the entry point to the ELF linker or loader. They
# conventionally recognize _start as their entry point. Use ld -e foo to
# override the default.
.global _start
_start:
# same as write(1, msg, len)
movl $len, %edx
movl $msg, %ecx
movl $1, %ebx
movl $4, %eax # the system call number of write() is 4.
int $0x80 # call kernel
# exit(0)
movl $0, %ebx
movl $1, %eax # exit() is 1
int $0x80
msg:
.ascii "Hello, world!\n"
len = . - msg # length of string
.text # section declaration
# we must export the entry point to the ELF linker or loader. They
# conventionally recognize _start as their entry point. Use ld -e foo to
# override the default.
.global _start
_start:
# same as write(1, msg, len)
movl $len, %edx
movl $msg, %ecx
movl $1, %ebx
movl $4, %eax # the system call number of write() is 4.
int $0x80 # call kernel
# exit(0)
movl $0, %ebx
movl $1, %eax # exit() is 1
int $0x80