gpt4 book ai didi

assembly - x86 控制台滚动后出现奇怪的打印

转载 作者:行者123 更新时间:2023-12-02 20:05:40 25 4
gpt4 key购买 nike

我有以下功能:

printRows proc
mov cx, 25
printRowsLoop:
mov si, 0
printSingleRowLoop:

mov ah, 3 ;save current cursor position at dx (dh:dl)
int 10h

push dx ;keep the position for later

mov ah, 2
mov dl, '&'
int 21h ; print '&' char in the current curser position

pop dx ; restore dx

add dl, 5 ; increase the column of it with a const number (so it would look like a square)
mov ah, 2
int 10h

inc si
cmp si, 3 ; print 3 '&' in each row
jne printSingleRowLoop

mov dl, 13 ; result of these 3 groups of commands should be 2 new lines
mov ah, 2
int 21h

mov dl, 10
;mov ah, 2 ; ah is alredy 2
int 21h

;mov dl, 10 ; dl is already 10
;mov ah,2 ; ah is already 2
int 21h

loop printRowsLoop ; print (cx) lines
ret

printRows endp

它的输出应该是在 this screenshot 中看到的 - 这就是它的输出(至少在开始时)

但是,在“好”输出填充控制台后(当需要“滚动”时),它不再打印每个 '&' 之间的空格,而是仅在新行 as can be seen here 中打印每个空格。

什么可能导致这种奇怪的行为?我究竟做错了什么?我该如何解决这个问题?

我使用的是emu8086。

最佳答案

您应该最后打印回车符(13 ascii 代码)。

我还包括了 Fifoernik我的回答中的提示。

printRows proc
mov cx, 25
printRowsLoop:
mov si, 0
printSingleRowLoop:

push cx
mov bh, 0
mov ah, 3 ;save current cursor position at dx (dh:dl)
int 10h
pop cx


push dx ;keep the position for later

mov ah, 2
mov dl, '&'
int 21h ; print '&' char in the current curser position

pop dx ; restore dx

mov bh, 0
add dl, 5 ; increase the column of it with a const number (so it would look like a square)
mov ah, 2
int 10h

inc si
cmp si, 3 ; print 3 '&' in each row
jne printSingleRowLoop


mov dl, 10
;mov ah, 2 ; ah is alredy 2
int 21h

;mov dl, 10 ; dl is already 10
;mov ah,2 ; ah is already 2
int 21h

mov dl, 13 ; <<<<<<<<<<<<<<<<<<<<< print the carriage return last!
;mov ah, 2 ; ah is already 2
int 21h

loop printRowsLoop ; print (cx) lines
ret

printRows endp

不需要额外的空格字符:)

关于assembly - x86 控制台滚动后出现奇怪的打印,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37579098/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com