首页 > 解决方案 > 如何在nasm屏幕上的指定位置写入文本?

问题描述

所以我有一个显示文本的程序(“Work was done to”),然后计数到 100% 并显示过程,但问题是我不想在显示新百分比之前总是打印文本。那么如何在屏幕上的指定位置插入文本以覆盖其他文本?

现在的样子

Work was done to 1%
2%
3%
...

我想成为怎样的人

工作完成到 1%(这个百分比只是用新的百分比覆盖)

cpu 386
bits 16
org 0h

start:
    ...

;=====================================================================================================================    

    mov ah, 0x07               ;function to call with interrupt
    mov al, 0x00               ;scroll whole window
    mov bh, 0x07               ;background color
    mov cx, 0x0000             ;row 0,col 0
    mov dx, 0x184f
    int 0x10

    mov si, msg1
    call print_str
    mov eax, [PERCENT]

next:
    inc eax
    mov di, strbuf             ;ES:DI points to string buffer to store to
    call uint32_to_str         ;Convert 32-bit unsigned value in EAX to ASCII string

    mov si, di                 ;DS:SI points to string buffer to print
    call print_str

    mov si, msg2
    call print_str

    cmp eax, 100               ;End loop at 100
    jl next                    ;Continue until we reach limit

done:
    hlt
    jmp done

;=====================================================================================================================    

print_str:
    ...

;=====================================================================================================================    

uint32_to_str:
    ...

;=====================================================================================================================

MBR_Signature:
    msg1 db 13,10,'   Work was done to ',0
    msg2 db '%',0
    PERCENT dd 0
    strbuf times 11 db 0
    times 510-($-$$) db 0
    db 55h,0aah
    times 4096-($-$$) db 0

标签: assemblynasmx86-16bootloader

解决方案


对不起,忘记答案了,我找到了答案。这是我使用的代码,感谢Peter Cordes,当然,我在源代码中修改了dh和,并从 msg2 中删除 ->dl10,13

mov dh, 0           ;Cursor position line
mov dl, 0           ;Cursor position column
mov ah, 02h         ;Set cursor position function
mov bh, 0           ;Page number
int 10h             ;Interrupt call

推荐阅读