7A.''What is your name' Microprocessor lab program [4th sem VTU]

vtu mp 7a

Q) Read your name from the keyboard and display it at a specified location on the screen in front of the message What is your name? You must clear the entire screen before display.

This program will take your name as the input. And display the name at the center of the screen in front of “what is your name?” message.

Algorithm:
Step 1: Read a string (i.e., Enter your name) character by character, using 01H service number and store it in a location.
Step 2: Clear the screen.
Step 3: Set the cursor position on the screen using the BIOS service ‘02H’.
Step 4: Display the stored string character by character, using ‘02H’.
Step 5: Stop.

CODE:


Explanation:
  • .MODEL SMALL 
  • DISPLAY MACRO MSG 
  • LEA DX,MSG 
  • MOV AH,09H 
  • INT 21H 
  • ENDM
As usual, one data and one code segment each.
DISPLAY macro takes one string argument as the parameter and displays the same using DOS service 09H on Interrupt 21H.
ENDM is the end of the macro.

  • CLRSCR MACRO   
  • MOV AH,00H 
  • MOV AL,02H 
  • INT 10H 
  • ENDM
CLRSCR macro is used in the program to clear the contents of the screen.

How to clear the screen in 8086 microprocessor programming?
You can do this by moving 00H in AH register and 02H in AL register. And on Interrupt 10H, screen will be cleared.
[INT 10H is related to all the screen related procedures, like clearing the screen and setting cursor to a position on screen.]

  • SETCUR MACRO X,Y 
  • MOV DH,Y         
  • MOV DL,X 
  • MOV AH,02H 
  • INT 10H 
  • ENDM
SETCUR macro is used in the program to set the cursor to a defined X and Y co-ordinate of the screen.

How to set cursor in 8086 microprocessor programming (to a specified <row,column> co-ordinate)?
You can do this by placing your ‘ROW’ value in DH register and ‘COLUMN’ value in DL register and move 02H to AH register and then call ‘INT 10H’ interrupt.
Same is done above with row,col as x,y in the parameter to the macro.



  • READ MACRO N   
  • MOV AH,01H 
  • INT 21H 
  • ENDM
READ macro reads a character from the keyboard using ‘01H’ service on Interrupt 21H.

  • WRITE MACRO N 
  • MOV AH,02H     
  • INT 21H 
  • ENDM
WRITE macro displays a character on the screen using ‘02H’ DOS service.


  • .DATA 
  • MSG DB "WHAT IS YOUR NAME? $" 
  • NAME1 DB 50 DUP (?) 
  • WAT DB 10,13,"ENTER YOUR NAME:$"
This is data segment with two messages “What is your name” and “Enter your name” terminated with ‘$’.
NAME1 is the 50 byte location to store the name that user enters. Initially assigned to nothing/Null using DUP(?) instruction. 10,13 have their usual meanings.(as discussed in the previous programs)

  • .CODE 
  • MOV AX,@DATA 
  • MOV DS,AX
  • LEA SI,NAME1
  •  LEA DX,WAT 
  • MOV AH,09H 
  • INT 21H
Code segment begins here. Data segment is initialized here using the usual commands. (second and third line in the snippet).
NAME1’s effective address is loaded in SI register to index the string.
WAT message (“Enter your name”), is printed by using ‘09H’ service on Interrupt 21H. (in the last three lines).

  • UP: 
  • READ NAME
  • MOV [SI],AL 
  • INC SI 
  • CMP AL,0DH 
  • JE D1 
  • JNE UP
This is to read your name.
UP is the label.
A character is read using READ macro(discussed above). NAME is just a dummy parameter passed because the macro definition contains a parameter We know that input taken using ‘01H’ is stored in AL register. So it is moved to the string using ( MOV [SI],AL).
SI is incremented for the storing of the next character.
Entered character is compared with ‘Enter’ key (whose ASCII is 0DH). If it is equal, then we need to stop taking more characters and go to display part.That is done using ( JE D1).

If not equal to ‘Enter’ key, next character is taken using macro. ( JNE UP).
This way, characters are continuously taken and stored until ‘Enter’ key was pressed.

  • D1: 
  • CLRSCR 
  • SETCUR 0BH,18H 
  • DISPLAY MSG
This is to clear the screen and Display “WHAT IS YOUR NAME?” at the center of the screen.
CLRSCR is used to clear the screen.
SETCUR places the cursor to the center (center of the screen co-ordinates are 0BH and 18H, you got to remember)
DISPLAY macro is called with MSG as parameter to print the message.
  • LEA SI,NAME1
  • UP2: 
  • WRITE NAME 
  • MOV DL,[SI] 
  • INC SI 
  • CMP DL,0DH 
  • JNE UP2
Now we need to display the name contained in NAME1. SI is initialized with offset of NAME1.(first character’s location).
UP2 is the label.
WRITE macro is called to print a character using ‘02H’ service. We know from the concept of 02H that character present in the DL register is displayed during the call of 02H on interrupt 21H.
So move [SI],(character present at location pointed by SI) into DL register. Increment SI to point to the next character in the string.
Compare DL with ‘Enter key,0DH’ (CMP DL,0DH) and print only if it is ‘not equal’. Which is accomplished by (JNE UP2).

  • MOV AH,4CH 
  • INT 21H 
  • END
Program is terminated at last using 4CH into AH and INT 21H as usual.
END is the end of the program.


Output:
ENTER YOUR NAME: CODESHUFFLE
WHAT IS YOUR NAME? (at the center)  CODESHUFFLE

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!