3

我有以下功能:

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

它的输出应该是这个屏幕截图中看到的- 这是它的输出(至少在开始时)

但是,在“好”输出填满控制台之后(当它需要“滚动”时)它不再打印每个“&”之间的那些空格,而是将它们中的每一个打印在一个新行中,如此处所示.

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

我正在使用emu8086。

4

3 回答 3

4

您应该最后打印回车符(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

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

于 2016-06-03T21:19:53.787 回答
2

您的代码有一些问题:

  • BIOS 游标函数需要指定 BH 参数。它代表显示页面。最好设置为零。

  • BIOS GetCursor 调用将破坏循环控制所需的 CX 寄存器。您实际上并不需要 CX 中返回的值,因此只需 PUSH/POP 即可。

用这个:

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

通常这些更正不会解决滚动问题,但emu8086是一个有很多问题的程序。你可能会走运!

于 2016-06-02T10:48:56.290 回答
0

问题是您插入换行符的方式。您所做的是显示 char 13, 10, 10。解决方案是在换行符 (13, 10, 10, ' ') 后显示一个空格:

mov dl, ' '
mov ah, 2
int 21h

要对齐第一行,我们必须在开头显示另一个空格:

printRows proc
    mov ah, 2    ;<=============================================
    mov dl, ' '  ;<=============================================
    int 21h      ;<=============================================

    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

        mov dl, ' ' ;<=============================================
        mov ah, 2   ;<=============================================
        int 21h     ;<=============================================

        loop printRowsLoop  ; print (cx) lines 
    ret

printRows endp
于 2016-06-02T21:40:13.317 回答