程序集打印输出意外结果:只是一个“". S" [英] Assembly Printing Outputs Unexpected Result: just an " S"
问题描述
我对汇编程序编程还比较陌生,想知道为什么我的代码不能显示预期的字符串.完成后,该项目应该是引导加载程序.我正在使用命令nasm -f bin boot.asm -o boot.bin
进行编译.编译期间没有错误.
I'm relatively new to assembly programming and was wondering why my code does not print the expected strings. This project is supposed to be a bootloader when finished. I am compiling using the command nasm -f bin boot.asm -o boot.bin
. There are no errors during compilation.
boot.asm
bits 16
org 0x7C00
%include "print.asm"
%include "text.asm"
boot:
mov si, boot_string_00
call print
mov si, boot_string_01
call print
times 510 - ($-$$) db 0
dw 0xAA55
print.asm
print:
mov ah, 0x0E
.print_loop:
lodsb
or al, al
je .print_done
int 0x10
jmp .print_loop
.print_done:
cli
ret
text.asm
boot_string_00: db "Placeholder OS Title v0.0.1", 0
boot_string_01: db "Loading Operating system", 0
预期输出:
PlaceHolder OS Title v0.0.1Loading Operating System
实际输出:
S
此外,我想知道如何在汇编中实现换行符,以便仅在字符串中使用'\ n'.
Also, I was wondering how i could implement newlines in assembly so that i could just use '\n' in my strings.
推荐答案
您已在Bootloader的顶部添加了内容,它将首先执行.相反,请包含一些额外的功能,使它们不在执行的主要路径中,而只能通过调用来实现.
You included stuff at the top of your bootloader, where it will executes first. Instead include extra functions where they aren't in the main path of execution and are only reached by call.
请尝试.根据评论,我编辑了代码
Please try. According to the comments I edited the code
boot.asm:
[bits 16]
[org 0x7c00]
boot:
xor ax, ax
mov ds, ax ; set up DS to make sure it matches our ORG
mov si, boot_string_00
call println
mov si, boot_string_01
call println
finish: ; fall into a hlt loop to save power when we're done
hlt
jmp finish
%include "printf.asm" ; not reachable except by call to labels in this file
%include "text.S"
times 510-($-$$) db 0
dw 0xaa55
printf.asm:
print:
mov ah, 0x0E ; call number for int 0x10 screen output
print_loop:
lodsb
test al, al
je print_done
int 0x10
jmp print_loop
print_done:
ret
println:
call print
mov si, line_end
call print
ret
文本.S:
boot_string_00: db "Placeholder OS Title v0.0.1", 0
boot_string_01: db "Loading Operating system", 0
line_end: db 0xD, 0xA, 0
(编者注:自己修复了此代码,而不是试图描述注释中的更改)
(Editor's note: fixed this code myself instead of trying to describe the change in comments)
这篇关于程序集打印输出意外结果:只是一个“". S"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!