小编Hoo*_*Man的帖子

在NASM中,内存中彼此相邻的标签导致打印问题

在NASM中编程时遇到问题。我正在学习如何纯粹以汇编形式开发OS,并且已经开始创建引导加载程序。

我目前的目标是打印“你好,世界!” 和“再见!” 使用BIOS中断0x10。

在屏幕上打印值时出现了我似乎遇到的问题。内存中两个标签似乎彼此相邻,导致打印一个字符串以打印另一字符串的内容。

为什么不在hlen第一个字符串的末尾停止循环?

    [org 0x7c00]

    mov ah, 0x0e

    mov bx, HELLO_MSG
    mov cx, hlen                                                                                                                                              
    call print_string

    mov bx, GOODBYE_MSG
    mov cx, glen                                                                                                                                              
    call print_string

    jmp $

    %include "print_string.asm"


    HELLO_MSG db 'Hello, World!',0
    GOODBYE_MSG db 'Goodbye!',0


    hlen equ $ - HELLO_MSG
    glen equ $ - GOODBYE_MSG

    times 510-($-$$) db 0
    dw 0xaa55
Run Code Online (Sandbox Code Playgroud)

臭虫:

  1. 两次打印再见消息

    这是由于HELLO_MSG打印Hello, World!Goodbye!。我相信这是因为标签位于内存中标签的Hello_MSG旁边GOODBYE_MSG

;;;print_string.asm
print_string:                   ;cx = string length                                                                                                                                                          
                                ;bX = string label - memory offset …
Run Code Online (Sandbox Code Playgroud)

x86 assembly nasm labels

3
推荐指数
1
解决办法
189
查看次数

标签 统计

assembly ×1

labels ×1

nasm ×1

x86 ×1