顶部带有 %include 的组件 - 打印输出意外结果:只是一个"" [英] Assembly with %include at the top - Printing Outputs Unexpected Result: just an " S"

查看:28
本文介绍了顶部带有 %include 的组件 - 打印输出意外结果:只是一个""的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对汇编编程比较陌生,想知道为什么我的代码不打印预期的字符串.这个项目在完成后应该是一个引导加载程序.我正在使用命令 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.1加载操作系统

实际输出:

S

另外,我想知道如何在汇编中实现换行符,以便我可以在我的字符串中使用 '\n'.

Also, I was wondering how i could implement newlines in assembly so that i could just use '\n' in my strings.

推荐答案

您在引导加载程序的顶部包含了一些东西,它将首先执行.而是包含不在主要执行路径中并且只能通过 call 访问的额外函数.

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.

这应该可行,将 %include 指令放在可以安全放置额外函数或数据的地方,就像将它们全部写入一个文件一样.

This should work, placing the %include directives where it's safe to put extra function or data, just like if you were writing them all in one file.

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

text.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

这篇关于顶部带有 %include 的组件 - 打印输出意外结果:只是一个""的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆