2013-02-15 61 views
1

我找到了“hello world”并写下了它。 纳米hello.s我如何开始学习asm(gas)?

这个代码

.data 
msg: 
.string "Hello, world!\n" 
len = . - msg 
.text 
global _start 
_start: 
    movl $len,%edx 
    movl $msg,%ecx 
    movl $1,%ebx 
    movl $4,%eax 
    int  $0x80 
    movl $0,%ebx 
    movl $1,%eax 
    int  $0x80 

我做as -o hello.o hello.s 我给了一个错误

hello.s:6: Error: no such instruction: global _start 

delete global _start. 

我做

ld -s -o hello.o hello* 

error 

ld: hello: No such file: No such file or directory 

上午在哪里我错了?

p/s debian,amd64。

+0

很难说出你在问什么。当您遇到有关“global _start”的错误时,您确实运行了汇编程序。您应该查看汇编器的手册以查看该行的错误。也许它不应该有一个空间或全球需要一个“。”前面。 – 2013-02-15 19:15:49

+0

也可以使用'gcc'编译器,并查看其生成的汇编代码,例如'gcc -Wall -fverbose-asm -O -S file.c'然后查看'file.s' – 2013-02-15 21:40:10

回答

2

尝试.globl _start.global _start

如果遇到入口点问题,您可以尝试unundeccored start

最后,如果您制作的是64位可执行文件,则可能需要使用不同的系统调用接口,而不是int 0x80,而是syscall。更多关于那here

+0

此外......'ld -o hello hello.o'' -o'开关指定输出文件名,'' hello.o'是ld正在处理的文件。从64位ld中获取32位代码,'-m elf_i386'。旧的'int 0x80'系统调用将在64位代码中工作,但它不正确。 '推reg32'将无法在64位代码中工作! – 2013-02-15 21:14:04