1

我正在使用0xa字符串末尾的指令来创建换行符,以便打印的最后一个字符串不会进入下一个。

mov bx, MESSAGE
call print_string

mov bx, ANOTHER
call print_string

hlt

print_string:
    pusha

    string_loop:
        mov al, [bx]
        cmp al, 0
        jne print_char

        popa
        ret

        print_char:
            mov ah, 0x0e
            int 0x10
            add bx, 1
    jmp string_loop

;global vars
MESSAGE: db 'Example string',0xa,0
ANOTHER: db 'Another example string',0xa,0

;padding/magic number
times 510-($-$$) db 0
dw 0xaa55

唯一的问题是,虽然字符串确实在最后一行下方打印了一行,但新行不会重置屏幕上的 x 位置,因此它不是直接在前一个字符串下方打印,而是在前一个字符串下方和之后打印.

示例输出:

Example string
              Another example string

如何编写此代码以使字符串直接打印在前一个字符串下?

4

1 回答 1

2

如何处理 Jester 的评论(在换行符旁边添加回车):

MESSAGE: db 'Example string',13,10,0
ANOTHER: db 'Another example string',13,10,0

如何处理 Ped7g 的评论(更改BXSI设置BLandBH参数):

mov bx, 0007h       ;Display page 0, graphics color 7
mov si, MESSAGE
call print_string
...
string_loop:
    mov al, [si]
    ...
    add si, 1
    jmp string_loop

Since this is bootloader code (times 510-($-$$) db 0 dw 0xaa55) and that ORG 0 is the default, you should best explicitely set the DS segment register at zero. Don't trust your executing environment for this!

xor     ax, ax
mov     ds, ax

Put this before anything else.

于 2016-12-04T21:36:16.457 回答