从引导加载程序打印字符

发布于 2024-08-17 21:32:25 字数 1365 浏览 3 评论 0原文

我正在尝试使用代码从引导加载程序打印字符

[BITS 16]   ;Tells the assembler that its a 16 bit code
[ORG 0x7C00]    ;Origin, tell the assembler that where the code will
    ;be in memory after it is been loaded

MOV AL, 65
CALL PrintCharacter
JMP $       ;Infinite loop, hang it here.


PrintCharacter: ;Procedure to print character on screen
    ;Assume that ASCII value is in register AL
MOV AH, 0x0E    ;Tell BIOS that we need to print one charater on screen.
MOV BH, 0x00    ;Page no.
MOV BL, 0x07    ;Text attribute 0x07 is lightgrey font on black background

INT 0x10    ;Call video interrupt
RET     ;Return to calling procedure

TIMES 510 - ($ - $$) db 0   ;Fill the rest of sector with 0
DW 0xAA55           ;Add boot signature at the end of bootloader

按照 编写 Hello World Bootloader。但它只是挂起而不打印任何内容。我们如何调试这个?我已使用以下代码成功创建了挂起引导加载程序,

[BITS 16]   ;tell the assembler that its a 16 bit code
[ORG 0x7C00]    ;Origin, tell the assembler that where the code will
;be in memory after it is been loaded

JMP $       ;infinite loop

TIMES 510 - ($ - $$) db 0   ;fill the rest of sector with 0
DW 0xAA55           ; add boot signature at the end of bootloader

我正在 VMware 3.0.0 build-203739 上测试我的代码。

I am trying to print character from boot loader using code

[BITS 16]   ;Tells the assembler that its a 16 bit code
[ORG 0x7C00]    ;Origin, tell the assembler that where the code will
    ;be in memory after it is been loaded

MOV AL, 65
CALL PrintCharacter
JMP $       ;Infinite loop, hang it here.


PrintCharacter: ;Procedure to print character on screen
    ;Assume that ASCII value is in register AL
MOV AH, 0x0E    ;Tell BIOS that we need to print one charater on screen.
MOV BH, 0x00    ;Page no.
MOV BL, 0x07    ;Text attribute 0x07 is lightgrey font on black background

INT 0x10    ;Call video interrupt
RET     ;Return to calling procedure

TIMES 510 - ($ - $) db 0   ;Fill the rest of sector with 0
DW 0xAA55           ;Add boot signature at the end of bootloader

As directed in Writing Hello World Bootloader. But it just hangs without printing anything. How can we debug this ? I have successfully created hanging boot loader using following code

[BITS 16]   ;tell the assembler that its a 16 bit code
[ORG 0x7C00]    ;Origin, tell the assembler that where the code will
;be in memory after it is been loaded

JMP $       ;infinite loop

TIMES 510 - ($ - $) db 0   ;fill the rest of sector with 0
DW 0xAA55           ; add boot signature at the end of bootloader

I am testing my code on VMware 3.0.0 build-203739.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

毁我热情 2024-08-24 21:32:25

要调试实模式 X86,您可以尝试与 Dosbox 集成的调试器。

For debugging real-mode X86, you can try the debugger integrated with Dosbox.

七禾 2024-08-24 21:32:25
[BITS 16]       ; We need 16-bit intructions for Real mode
[ORG 0x7C00]    ; The BIOS loads the boot sector into memory location
0x7C00
       mov ah, 0Eh     ; We want to print a single character
       mov al, 'A'     ; That character is 'A'
       mov bh, 0Eh     ; White text on black background, not blinking
       mov bl, 0       ; Page number 0
       int 10h

hang:
       jmp hang        ; Loop, self-jump

times 510-($-$) db 0  ; Fill the rest of the files with zeros, until we reach 510 bytes
dw 0AA55h              ; Our boot sector identifyer

-
我在Windows下的nasm和Bochs的帮助下成功运行了这段代码。
指示 :-
1)nasm -f bin booting.asm -o booting.bin
“-f bin”指定纯二进制格式。
2)将文件复制到 Bochs 目录中并使用 booting.bin 作为软盘运行它,我们就完成了

我什至通过在闪存驱动器上刻录 bin 文件的映像来测试它,并在启动该闪存驱动器时我能够得到我所期望的。您可以获取所有这些信息
http://www.weethet.nl/english/hardware_bootfromusbstick.php

[BITS 16]       ; We need 16-bit intructions for Real mode
[ORG 0x7C00]    ; The BIOS loads the boot sector into memory location
0x7C00
       mov ah, 0Eh     ; We want to print a single character
       mov al, 'A'     ; That character is 'A'
       mov bh, 0Eh     ; White text on black background, not blinking
       mov bl, 0       ; Page number 0
       int 10h

hang:
       jmp hang        ; Loop, self-jump

times 510-($-$) db 0  ; Fill the rest of the files with zeros, until we reach 510 bytes
dw 0AA55h              ; Our boot sector identifyer

-
i successfully managed to run this code with the help of nasm and Bochs under windows.
Instructions :-
1)nasm -f bin booting.asm -o booting.bin
The '-f bin' specifies the format to plain binary.
2)Copy the file into Bochs' directory and run it with the booting.bin as a floppy and we're done

I even tested it by burning the image of bin file on a flash drive and on booting that flash drive i was able to get what i expected. You can get all that info on
http://www.weethet.nl/english/hardware_bootfromusbstick.php

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文