NASM - error: label or instruction expected at start of line
NASM - error: label or instruction expected at start of line
自从在 MS-DOS 3.31 中调试以来,我还没有编写过汇编代码,所以 NASM 并且在机器代码中使用标签作为变量的概念对于我。我正在使用 Visual Studio 2015 和 Asmdude 语法荧光笔。我正在使用 NASM 版本 2.12.01 compiled on Mar 17 2016
我目前正在阅读名为 Writing a Simple Operating System from Scratch 的操作系统开发 PDF。我正在关注其中一个示例,但无法将示例获取到 assemble。
请原谅过时的代码结构,我觉得这样更容易阅读。
[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 上调试运行
在使用 iuppiter 后,确定 Visual Studio 正在使用错误的文件编码编写汇编文件。副作用是 NASM 无法解析文件并退出:
boot.asm:1: error: label or instruction expected at start of line
要在 Visual Studio 2015 年解决此问题,可以使用以下过程以不同的编码保存文件:
- 打开汇编文件
- Select
File/Save as...
在菜单上
- 在文件选择器的底部 window 单击底部
Save
按钮旁边的向下箭头
- 点击
Save with encoding...
- Select
Western European (Windows) Codepage 1252
(这应该是纯文本)
- 点击
OK
自从在 MS-DOS 3.31 中调试以来,我还没有编写过汇编代码,所以 NASM 并且在机器代码中使用标签作为变量的概念对于我。我正在使用 Visual Studio 2015 和 Asmdude 语法荧光笔。我正在使用 NASM 版本 2.12.01 compiled on Mar 17 2016
我目前正在阅读名为 Writing a Simple Operating System from Scratch 的操作系统开发 PDF。我正在关注其中一个示例,但无法将示例获取到 assemble。
请原谅过时的代码结构,我觉得这样更容易阅读。
[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 上调试运行
在使用 iuppiter 后,确定 Visual Studio 正在使用错误的文件编码编写汇编文件。副作用是 NASM 无法解析文件并退出:
boot.asm:1: error: label or instruction expected at start of line
要在 Visual Studio 2015 年解决此问题,可以使用以下过程以不同的编码保存文件:
- 打开汇编文件
- Select
File/Save as...
在菜单上 - 在文件选择器的底部 window 单击底部
Save
按钮旁边的向下箭头 - 点击
Save with encoding...
- Select
Western European (Windows) Codepage 1252
(这应该是纯文本) - 点击
OK