【问题标题】:NASM - error: label or instruction expected at start of lineNASM - 错误:行首需要标签或指令
【发布时间】:2016-04-10 01:27:13
【问题描述】:

自从 MS-DOS 3.31 中的 Debug 以来,我还没有编写过汇编代码,所以 NASM 以及在机器代码中使用标签作为变量的概念对我来说是全新的。我正在使用带有 Asmdude 语法荧光笔的 Visual Studio 2015。我正在使用 NASM 版本 2.12.01 compiled on Mar 17 2016

我目前正在阅读名为Writing a Simple Operating System from Scratch 的关于操作系统开发的PDF。我正在关注其中一个示例,但无法组装该示例。

请原谅陈旧的代码结构,我觉得这样更容易阅读。

                    [BITS 16]
                    [ORG 0x7C00]
                    MOV BP, 0x8000 ; Set the base of the stack a little above where BIOS
                    MOV SP, BP ; loads our boot sector - so it won 't overwrite us.
ProgramOrigin:      MOV BX, StartText ; Put startup text into BX
                    CALL PrintString ;Call PrintString Function
                    JMP EndProgram ;Continue to end of program
PrintString:        PUSHA ; Push all registers onto stack 
                    MOV AH, 0x0E ; BIOS Teletype
NextChar:           MOV AL, [BX] ; Move the contents of memory segment at address in BX into AL
                    CMP AL, 0x00 ; if (AL == 00) it is the end of the string
                    JE EndPrint ; End function
                    INT 0x10 ;Interrupt to print character to screen
                    ADD BX, 1 ;ELSE increment address in BX
                    JMP nextChar ;Repeat
EndPrint:           POPA ;Return original Register values 
                    RET ;Return from function
StartText:          DB 'Kernel v0.01', 0x00
errText:            DB 'Error', 0x00
notFoundText:       DB 'Not Found', 0x00
EndProgram:         times 510 -($-$$) DB 0
                    DW 0xAA55

我确实为 PrintString 函数添加了一些我自己的代码,但我认为我这样做是正确的,因为它可以在我的 DOS VM 上进行调试

【问题讨论】:

  • NASM 在标签方面区分大小写,请尝试使用JMP NextChar 而不是JMP nextChar。您应该能够使用 nasm -f bin boot.asm -o boot.bin 之类的东西进行组装。引导加载程序不会返回任何地方,因此您应该考虑在代码完成后将代码置于无限循环中,例如 JMP $ 或最好是 CLI EndLoop: HLT jmp EndLoop
  • 仍然得到同样的错误,thanx 虽然。
  • 帖子标题“boot.asm:1: error: label or instruction expected at the start of line”中的那个。我按照您的建议重新格式化了批处理文件中的参数:G:\nasm\nasm.exe -f bin boot.asm -o bootsector.bin。我只是在组装,看看我添加的打印功能真的可以工作。
  • Visual Studio 2015,ASMDude 扩展
  • 还是一样的。

标签: assembly visual-studio-2015 nasm bootloader x86-16


【解决方案1】:

在使用iuppiter 之后,确定Visual Studio 正在编写具有错误文件编码的汇编文件。副作用是 NASM 无法解析文件并退出:

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

要在 Visual Studio 2015 中解决此问题,可以使用以下过程以不同的编码保存文件:

  1. 打开汇编文件
  2. 在菜单上选择File/Save as...
  3. 在文件选择器窗口的底部,单击底部Save 按钮旁边的向下箭头
  4. 点击Save with encoding...
  5. 选择Western European (Windows) Codepage 1252(这应该是纯文本)
  6. 点击OK

【讨论】:

    猜你喜欢
    • 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
    相关资源
    最近更新 更多