【发布时间】: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 $或最好是CLIEndLoop: HLTjmp 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