首页 > 解决方案 > Emu8086 - 尝试向下移动光标时光标位置不正确

问题描述

我正在测试使用emu8086将文本写入屏幕。我正在尝试打印带有字母 A 到 I 的 3x3 网格。我想这不是向下移动光标(执行回车)的传统方法,但它应该可以工作。

org 100h

;
; Initialise
;
                   
; Set video mode
mov AL, 13h
mov AH, 0
int 10h

; Set cursor position
mov DH, 1
mov DL, 1
mov BH, 0
mov AH, 2
int 10h

; Set cursor intensity/blinking
mov ax, 1003h
mov bx, 0
int 10h

; Set attribute to white foreground, black background
mov BL, 0Fh
    
    
call print_grid
jmp end

print_char PROC
                                                         
    mov AH, 09h ; Set interrupt to print
    mov CX, 1 ; So that the character is only printed once
    
    int 10h
    
    inc DL ; Incrementing the cursor position horizontally
    mov AH, 2h ; Set interrupt to set cursor position
    int 10h
      
    ret
print_char ENDP

carriage_return PROC
    inc DH ; Incrementing the cursor position vertically
    mov DL, 1 ; Resetting horizontal cursor position
    mov AH, 2h ; Set interrupt to set cursor position
    int 10h
    
    ret
    
carriage_return ENDP

; Prints the grid to the screen
print_grid PROC 
    
    ; Row 1
    
    mov AL, pos[0]
    call print_char
    
    mov AL, '|'
    call print_char
    
    mov AL, pos[1]
    call print_char
    
    mov AL, '|'
    call print_char
    
    mov AL, pos[2]
    call print_char
    
    call carriage_return
    
    ; Row 2
    
    mov AL, '-'
    call print_char
    
    mov AL, '+'
    call print_char
    
    mov AL, '-'
    call print_char
    
    mov AL, '+'
    call print_char
    
    mov AL, '-'
    call print_char
    
    call carriage_return
    
    ; Row 3
    
    mov AL, pos[3]
    call print_char
    
    mov AL, '|'
    call print_char
    
    mov AL, pos[4]
    call print_char
    
    mov AL, '|'
    call print_char
    
    mov AL, pos[5]
    call print_char
    
    call carriage_return
    
    ; Row 4
    
    mov AL, '-'
    call print_char
    
    mov AL, '+'
    call print_char
    
    mov AL, '-'
    call print_char
    
    mov AL, '+'
    call print_char
    
    mov AL, '-'
    call print_char
    
    call carriage_return
    
    ; Row 5
    
    mov AL, pos[6]
    call print_char
    
    mov AL, '|'
    call print_char
    
    mov AL, pos[7]
    call print_char
    
    mov AL, '|'
    call print_char
    
    mov AL, pos[8]
    call print_char
    
    call carriage_return
    
    ret
print_grid ENDP 

end:

ret

pos DB 65, 66, 67, 68, 69, 70, 71, 72, 73

虚拟屏幕上出现的是这个

我知道有更好的方法可以使用 emu8086 打印字符,例如 PRINT/PRINTN 宏,但我想尝试手动进行,所以我希望能回答为什么程序输出这个。尽管如果您愿意,欢迎使用有关改进此代码的一般提示。

标签: x86-16emu8086

解决方案


推荐阅读