Trying to set a value from input for coordinate X, but when I test the result, it seems that coordinate for X is random as it is showed at the bottom of CMD. How to pass an inputted value into DH register? It seems that not my desired value is passed but some random ASCII code.
mov ah,1;read value from input
int 21h
mov dh,al;Trying to pass a value from input x coordinate
mov dl,10 ;y coordinate
mov ah, 02h ;output
int 10h ;bios interruption
mov al, '1'
mov ah, 0Eh
int 10h
mov dx,offset test
mov ah,9
int 21h
Here is example: inputted value 5 for X. Other numbers are just already set coordinates, like:
mov dh,4
mov dl,10
The DOS.GetKey function 01h gives you an ASCII code in the AL register, eg. if the user presses 5 then AL will contain 53. If it's the value 5 that you're after, then simply subtract 48. Because the ASCII code for "0" is 48, you can write this conversion as sub al, '0'
.
mov ah, 01h ; DOS.GetKey
int 21h ; -> AL
sub al, 48
The BIOS.SetCursorPosition function 02h expects from you the desired column in DL, the desired row in DH, and the displaypage to use in the BH register. You have omitted the BH from your code, and have erroneously reversed the meaning of the DL and DH registers. Also, when dealing with character output, we don't talk about X and Y, but rather about Column and Row.
mov dl, al ; Column from input
mov dh, 10 ; Row
mov bh, 0 ; DisplayPage
mov ah, 02h ; BIOS.SetCursorPosition
int 10h
The BIOS.Teletype function 0Eh additionally expects in BL the color to be used in case the display would be in a graphics mode, and in BH the displaypage to use. If the Teletype
immediately follows the SetCursorPosition
, you don't need to repeat setting BH.
mov bx, 0007h ; DisplayPage BH=0, GraphicsColor BL=7 (White)
mov ax, 0E31h ; BIOS.Teletype AH=0Eh, Character AL='1' (49)
int 10h
Although the emu8086 emulator does not support the DisplayPage parameter in BH, you should learn and use the official BIOS api. Then at least your programs will have a chance when run outside of emu8086...