使用汇编级语言读取一对BCD输入坐标,将光标移动到屏幕指定位置
Read a pair of input co-ordinates in BCD and move the cursor tothe specified location on the screen using assembly level language
这是我的程序
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 以将其放置在屏幕中央,但是使用这个程序它的位置不是在中央。
我认为问题出在我进行输入时,因为当我通过将行值直接放入 dh 和 DL 寄存器中将行值直接设置为 12 并将列值设置为 40 时,光标直接位于中心。
有人可以帮帮我吗?谢谢
对于没有编写它的人来说,汇编中一堆未注释的行往往是一团乱七八糟的东西。
让我们一步一步来:
; 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
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
这是我的程序
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 以将其放置在屏幕中央,但是使用这个程序它的位置不是在中央。
我认为问题出在我进行输入时,因为当我通过将行值直接放入 dh 和 DL 寄存器中将行值直接设置为 12 并将列值设置为 40 时,光标直接位于中心。
有人可以帮帮我吗?谢谢
对于没有编写它的人来说,汇编中一堆未注释的行往往是一团乱七八糟的东西。
让我们一步一步来:
; 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
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