11A. Placing the cursor to given co-ordinates [VTU 4th sem MP lab]

vtu mp 11a

Q)  Read a pair of input co-ordinates in BCD and move the cursor to the specified location on the screen.

This program will place the cursor to the entered co-ordinates on the screen.

place the cursor to the entered co-ordinates on the screen.
Step 1: Display the message “Enter X-coordinate:”.
Step 2: Read the value of X-coordinate.
Step 3: Display the message “Enter Y- coordinate:”.
Step 4: Read the value of Y-Coordinate.
Step 5: Change the cursor position to (X,Y) position using ‘INT 10H’.
Step 6: Stop.

CODE:


Explanation:
  • .MODEL SMALL
  • PLACE MACRO X,Y
  • MOV AH,02H
  • MOV DH,Y
  • MOV DL,X
  • INT 10H
  • ENDM
One code and one data segment each.
PLACE is a macro to place the cursor to a specified location on the screen.
X,Y are parameters representing Column and row numbers for the co-ordinates.
Row is moved into DH and Column is moved into DL.
AH is loaded with 02H.
INT 10H places cursor to <row,col>=<DH,DL> co-ordinates.

  • DIS_MSG MACRO P1
  • MOV AH,09H
  • LEA DX,P1
  • INT 21H
  • ENDM
DIS_MSG displays the message using 09H service with INT 21H.
Same old fashioned method using LEA.

  • READ MACRO
  • MOV AH,01H
  • INT 21H
  • SUB AL,30H
  • MOV BL,10
  • MUL BL
  • MOV BL,AL
  • MOV AH,01H
  • INT 21H
  • SUB AL,30H
  • ADD AL,BL
  • ENDM

READ macro reads a two digit number (row,column)
First digit is read first and multiplied by 10 and stored in a register. And second digit is taken from the keyboard and added to the (first number *10).

For example,
if we were to enter the two digit number ‘27’.

We will first input 2 (the first digit) using 01H service. Its ASCII will be stored in AL register. Subtract 30H from AL to get the actual number. (AL=2 now)
MULTIPLY BL,10 will multiply the contents of AL register by 10 and store it in BL register. Now BL has 20.

Then get the second digit, which is 3, using 01H service. ASCII of 3 is stored in AL. Subtract 30H from AL to get the actual number. (AL=3 now)

ADD AL,BL adds AL and BL and stored it in AL.(AL=20+3=23 now).

Hurrah! Thereby We entered a two digit number. (now after explaining this much, the code becomes self explanatory)

  • .DATA
  • M1 DB 10,13,'ENTER X CO-ORDINATE:$'
  • M2 DB 10,13,'ENTER Y CO-ORDINATE:$'
  • X DB 0
  • Y DB 0
Data segment with appropriate display messages for User interface.
X and Y are two locations to store the Row and Column values initially set to value 0.

  • .CODE
  • START:  
  • MOV AX,@DATA
  • MOV DS,AX
Code segment begins and data segment is initialized.

  • DIS_MSG M1
  • READ
  • MOV X,AL
  • DIS_MSG M2
  • READ
  • MOV Y,AL
DIS_MSG macro is called to display the message “ENTER X CO-ORDINATE:” with M1 as the parameter.
READ takes a two digit number as explained above.
The read two digit number is stored into X (which is row)

Again,
DIS_MSG macro is called to display the message “ENTER Y CO-ORDINATE:” with M2 as the parameter.
READ takes a two digit number as explained above.
The read two digit number is stored into Y (which is column)

  • PLACE X,Y
  • MOV AH,01H
  • INT 21H
PLACE macro places the cursor at X,Y co-ordinate.
Next code is to hold the control until user presses a button. (otherwise, cursor will be placed at the location and program will terminate suddenly)
Take an input using 01H and after taking the input,terminate the program using 4CH.

  • MOV AH,4CH
  • INT 21H
  • END START
Program terminated using usual 4CH method. END is the end of the program.

Output:
ENTER X CO-ORDINATE: 12
ENTER Y CO-ORDINATE:16


[cursor will be placed at <12,16> co-ordinate].

He is a simple passionate tech freak who himself is an engineering student at Canara Engineering college. He likes App Development, Web designing, Blogging, Youtubing, Debugging and also is a CodeGeek!

Sharing is sexy!

Related Articles

Share your views about this article!