2013-02-15 116 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