且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

我的汇编函数打印一些字符串,但不打印其他字符串

更新时间:2023-11-14 10:43:58

BIOS 将始终从引导扇区的第一个字节开始执行,在您的情况下,它似乎是字符串,因此您正在执行数据.(事实上​​,您放入了一个名为 main 的标签不会影响这一点;没有任何东西可以查看它.)这可能是因为您的Hello world"没有了.字符串恰好对应于不会完全破坏所有内容的指令.

The BIOS will always start execution at the first byte of the boot sector, and in your case that appears to be the string, so you're executing data. (The fact that you put in a label called main doesn't affect this; nothing looks at it.) It could be that your "Hello world" string just happens to correspond to instructions that don't totally break everything.

尝试将字符串移动到所有代码之后,或者在它之前插入一个 jmp main.

Try moving the string to be after all the code, or else insert a jmp main before it.

此外,您的 ORG 指令和 ds 段之间存在不一致.您的引导扇区在线性地址 0x7c00 处加载.您可以在 segment:offset 形式中将其视为 0000:7c0007c0:0000 (或其他方式,如果您真的想要的话).因此,要访问引导扇区中的数据,您需要将 ds 加载为零并使用 [ORG 0x7c00],或者使用 ds 加载0x07c0 并使用 [ORG 0].但是,您的代码混合了两者.

Also, you have an inconsistency between your ORG directive and your ds segment. Your boot sector gets loaded at linear address 0x7c00. You can think of this in segment:offset form as 0000:7c00 or 07c0:0000 (or other ways in between if you really want). So to access data in the boot sector, you either need to load ds with zero and use [ORG 0x7c00], or else load ds with 0x07c0 and use [ORG 0]. However, your code mixes the two.