2017-01-29 72 views
0

我決定學習彙編的今天,因爲它似乎這是一個非常強大的工具,但我不知道從哪裏開始學習它,所以我用Google搜索了一下,發現這樣的: https://www.tutorialspoint.com/assembly_programming不能執行彙編程序

它告訴我安裝NASM和MinGW進行編譯和鏈接,所以我下載並安裝了它並確保它們都正常工作。

我複製給定的代碼

section .text 
    global _start  ;must be declared for linker (ld) 

_start:    ;tells linker entry point 
    mov edx,len  ;message length 
    mov ecx,msg  ;message to write 
    mov ebx,1  ;file descriptor (stdout) 
    mov eax,4  ;system call number (sys_write) 
    int 0x80  ;call kernel 

    mov eax,1  ;system call number (sys_exit) 
    int 0x80  ;call kernel 

section .data 
msg db 'Hello, world!', 0xa ;string to be printed 
len equ $ - msg  ;length of the string 

,並通過編寫

nasm -f elf hello.asm 
(later nasm -f win32 hello.asm) 

事後

ld hello.o -o hello.exe 
(later ld hello.obj -o hello.exe) 

它粘貼到名爲 「hello.asm」 一個空文件和編譯它並且它成功地創建了一個.exe文件,但是當我試圖執行它時,它只能打開風運行命令提示符並打開一個新窗口,提示「hello.exe不再工作」。

我知道這不會輸出任何東西,但它不應該至少運行?

我做錯了什麼?

使用:

  • Windows 7專業版64位
  • AMD FX 4350
  • NASM,02年2月12日
  • MinGW
+1

這是一個Linux教程,這不適用於Windows。 – tkausl

+0

所以組裝是特定的嗎? –

+2

不,但系統調用是('int 0x80') – tkausl

回答

0

你會需要一個不同的教程,正如用戶tkausl指出的,本教程適用於Linux x86_64位。

對於windows,如果你願意,你仍然可以使用NASM彙編程序和MinGW,但是由於調用的不同,你的代碼將會看起來不同,並且還需要你使用外部庫。

但是,我推薦使用適用於Windows的MASM,因爲它是由Microsoft設計的,並且還包含在具有其他工具的MASM32v8軟件包中。你可以從這裏得到MASM:http://www.masm32.com/

也有適用於Windows大會教程: https://www-s.acm.illinois.edu/sigwin/old/workshops/winasmtut.pdf

但是,如果你在使用NASM彙編的意圖,那麼你可以參考由caffiend張貼在這裏的答案: How to write hello world in assembler under Windows?