2017-01-07 21 views
-1

我學習ASM和現在看到了一個劇本,但我不能編譯:錯誤編譯一個簡單的組裝

section .text 
    global _start  ;must be declared for using gcc 
_start:      ;tell linker entry point 
    mov  edx, [ebp+input_file] 
    mov  eax, [edx+8] 
    movsx ecx, word ptr [eax] 
    push ecx 
    mov  edx, [ebp+input_file] 
    mov  eax, [edx+8] 
    push eax 
    mov  ecx, [ebp+var_8] 
    mov  edx, [ecx+2748h] 
    push edx 
    call memcpy 
    int  0x80  ;call kernel 
    mov  eax, 1  ;system call number (sys_exit) 
    int  0x80  ;call kernel 

section .data 

當我使用編譯此代碼:

nasm -f elf *.asm; ld -m elf_i386 -s -o demo *.o 

我得到這個結果:

Error: comma, colon, decorator or end of line expected after operand >
ld: cannot find *.o: No such file or directory

我該如何解決這個問題?

+2

您確定沒有該錯誤消息的行號?這將有助於更長時間的來源標記線路,這是造成問題的原因。 – Ped7g

+0

正是它是我試圖把它放在一個簡單的hello世界腳本中的一段代碼。現在我看到input_file,var_8是未定義的@Ped7g – reza

回答

1

ptr是NASM中未定義的關鍵詞。只要將其刪除(在第6行),您的代碼將被編譯:

movsx ecx, word [eax]