【问题标题】:nasm - error: label or instruction expected at the start of linenasm - 错误:行首需要标签或指令
【发布时间】:2014-06-16 18:33:08
【问题描述】:

您好,我对组装非常陌生(今天才开始),并且在完全按照this tutorial 中所说的操作时遇到了这个问题。我用这个文本制作了一个 asm 文件:

bits    16
org     0x7c00
jmp     Main

:In=  si = string, ah = 0eh, al = char, Out= character screen
Print:
lodsb
cmp     al, 0
je      Done
mov     ah, 0eh
int     10h
jmp     Print

Done:
ret

Main
mov     si, msg
call Print

cls
hlt

msg     db  "Hello World",0

times 510 - ($-$$)      db      0

dw      0xAA55

在我的带有 asm 文件的文件夹中,我有一个 nasm 和 nasmpath 的副本,我还有一个 bochs 的快捷方式。我想要做的是将其转换为 bin 文件。当我输入这个命令时:

nasm -f bin boot.asm -o boot.bin

我收到此错误

boot.asm:5: error: label or instruction expected at the start of line

我想知道这是一个糟糕的教程还是我输入错误。我也想知道“标签或说明”是什么意思。

【问题讨论】:

  • 第 5 行应该以分号开头,而不是冒号。
  • 好的,谢谢,但为什么要投反对票。我在帖子里说我是新人

标签: assembly nasm bochs


【解决方案1】:

你也应该在 Main 和 cls 后面加上冒号

bits    16
org     0x7c00
jmp     Main

;In=  si = string, ah = 0eh, al = char, Out= character screen
Print:
lodsb
cmp     al, 0
je      Done
mov     ah, 0eh
int     10h
jmp     Print

Done:
ret

Main:
mov     si, msg
call Print

cls:
hlt

msg     db  "Hello World",0

times 510 - ($-$$)      db      0

dw      0xAA55     

【讨论】:

    【解决方案2】:

    您在第 5 行使用了注释。要将一行标记为注释,您需要一个分号。 “标签或指令”的意思是,每一行必须是一个指令(一个操作码,如 mov、add、...),或者它必须是一个标签(如 Print:)或一个标签后跟一个指令。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-10-27
      • 1970-01-01
      • 2021-12-28
      • 1970-01-01
      • 2012-07-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多