在BCD中读取一对输入坐标,并使用汇编级语言将光标移动到屏幕上的指定位置



这是我的程序

display macro msg
lea dx,msg
mov ah,09h
int 21h
endm
.model small
.data
msg1 db 10h,13h,"Enter row$" 
msg2 db 10h,13h,"Enter Column$"
row db ?
col db ?
.code
mov ax,@data
mov ds,ax
display msg1
call read
mov row,al
display msg2
call read
mov col,al
mov ah,00
mov al,3
int 10h
mov ah,02
mov bh,00
mov dh,row
mov dl,col
int 10h
mov ah,01h
int 21h
mov ah,4ch
int 21h
read proc 
mov ah,01
int 21h
and al,0fh
mov bl,al
mov ah,01
int 21h
and al,0fh
mov ah,bl
MOV CL,4
SHL AH,CL
ADD AL,AH
ret 
read endp
end

所以我知道行和列的位置应该被给定为12和40,以将其放置在屏幕的中心,但是使用这个程序,它的位置不是在中心。

我认为问题是当我输入时,因为当我把行值直接作为12,列值作为40通过把它放在dh和DL寄存器直接游标在中心。

有谁能帮帮我吗?由于
mov ah,bl
MOV CL,4
SHL AH,CL
ADD AL,AH
ret

在此代码中,的十分之一乘以16。你需要乘以10。一个简单的方法是使用aad指令。

mov ah,bl
aad        ;This is AH * 10 + AL
ret

汇编中没有注释的一堆行对于不写它的人来说往往是一团乱七八糟的东西。

让我们一步一步来做:

; first of all, set the video mode
mov ah, 0x00 ; function: set video mode
mov al, 0x03 ; video mode: 0x03
int 0x10     
; set the cursor position to 0:0 (DH:DL)
mov ah, 0x02 ; function: set cursor position
xor bh, bh ; page: 0x00
xor dh, dh ; row: 0x00
xor dl, dl ; column: 0x00
int 0x10
; read row into DH
call read_num
mov dh, dl
; if you want to, you can read a separator character between them
; call read_num
; read column into DL
call read_num
; set the cursor position again to DH:DL
mov ah, 0x02 ; function: set cursor position
xor bh, bh ; bh: just to make sure BH remains 0x00
int 0x10
...
read_num: ; will read two decimal characters from input to DL
    ; DOS interrupt for reading a single characted
    mov ah, 0x01 ; function: read a character from STDIN
    int 0x21
    and al, 0x0F ; get the number from the ASCII code
    mov bl, 0x0A
    mul bl       ; move it to the place of tens
    mov dl, al      ; dl = al*10 
    ; DOS interrupt for reading another char
    mov ah, 0x01 ; function: read a character from STDIN
    int 0x21
    and al, 0x0F
    add dl, al      ; dl = dl + al
    ret

最新更新