Khacho
Khacho

Reputation: 301

Read a pair of input co-ordinates in BCD and move the cursor tothe specified location on the screen using assembly level language

This is the program I have

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

So I know that the row and column positions should be given as 12 and 40 to place it at center of the screen, but using this program it's position is not coming in center.

I think problem is when I'm taking input, because when I put row value directly as 12 and column value as 40 by putting it in dh and DL register directly cursor comes in center.

Can anyone help me please? Thanks

Upvotes: 1

Views: 352

Answers (2)

Sep Roland
Sep Roland

Reputation: 39546

mov ah,bl
MOV CL,4
SHL AH,CL
ADD AL,AH
ret

In this code you multiplied the tenths by 16. You need a multiplication by 10. A easy way is using the aad instruction.

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

Upvotes: 2

user35443
user35443

Reputation: 6413

An uncommented bunch of lines in assembly tends to be pretty much an unreadable mess to people who didn't write it.

Let's do it step by step:

; 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

Upvotes: 0

Related Questions