【问题标题】:Error in compiling a simple assembly编译简单程序集时出错
【发布时间】:2017-01-07 21:05:57
【问题描述】:

我正在学习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

我得到这个结果:

错误:操作数后应有逗号、冒号、装饰符或行尾>
ld: 找不到 *.o: 没有这样的文件或目录

我该如何解决这个问题?

【问题讨论】:

  • 您确定没有包含该错误消息的行号吗?如果源标记线较长,这会导致问题,这将有所帮助。
  • 正是我试图把它放在一个简单的 hello world 脚本中的一段代码。现在我看到 input_file,var_8 未定义 @Ped7g

标签: assembly x86 nasm


【解决方案1】:

ptr 是 NASM 中未定义的关键字。只需删除它(在第 6 行),您的代码就会编译:

movsx   ecx, word [eax]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-24
    • 2022-07-13
    • 2021-01-09
    • 1970-01-01
    • 2015-03-22
    相关资源
    最近更新 更多