Blogger news

Followers

Friday, February 21, 2014


ASSUME CS: CODE, DS: DATA

DATA SEGMENT                                       ; start of data segment
MSG1 DB 0DH, 0AH,'ENTER YOUR NAME : ', '$'
MSG2 DB 'WHAT IS YOUR NAME? ', '$'
STR  DB 25 DUP('  '), '$'                               ; 25 bytes of STR array (blank) is declared to store the user entered name.  
X DB 04H                                                      ; X coordinate value
Y DB 12H                                                      ; Y coordinate value
DATA ENDS

DISPLAY MACRO MSG                                       ; DISPLAY macro definition starts
MOV DX, OFFSET MSG
MOV AH, 09H                                               ; display the message whose offset is in DX using 09H
INT 21H                                                         ; with DOS 21H interrupt.
ENDM                                                            ; end of macro definition

CODE SEGMENT
START:
                      MOV AX, DATA                    ; data segment initialization
                      MOV DS, AX
      
                      DISPLAY MSG1                     ; invoke the DISPLAY macro to display MSG1
                      MOV SI, OFFSET STR               ; SI point to the 1st memory location of STR array
         BACK:  MOV AH, 01H                         ; read a character from keyboard using 01H service
                      INT 21H                                   ; with 21h interrupt, then compare with enter key
                      CMP AL, 0DH                         ; if yes terminate, otherwise store in STR array pointed by SI                   JE STOP                                 ; if yes terminate,
                      MOV [SI], AL                          ; otherwise store in STR array pointed by SI
                      INC SI                                      ; increment SI, to point to the next location of STR array
                      JMP BACK                                 ; jump to BACK to read the next character
          STOP:    MOV AH, 07H             ; service number to clear the screen
          MOV AL, 00H                         ; Number of lines to scroll; 00 blank screen.
                      MOV BH, 0FH                         ; attribute of character; 0F white and 00 black
          MOV CX, 00H                         ; CH=00 Y coordinate of upper left corner and
; CL=00 X coordinate of upper right corner.
                      MOV DH, 31H                         ; Number of rows;
                      MOV DL, 79H                         ; Number of columns;
                      INT 10H                                   ; BIOS interrupt to clear the screen is invoked
                      MOV AH, 02H                        ; service number to set the cursor
                      MOV BH, 00H                         ; set video Page number to 0
                     MOV DH, Y                       ; store row number in DH (Y coordinate)
                     MOV DL, X                        ; store the column number (X)  in DL register
                     INT 10H                                    ; BIOS interrupt to set the cursor is invoked.    
                     DISPLAY MSG2                                    ; invoke the DISPLAY macro to display MSG2.
                     DISPLAY STR                                ; invoke the DISPLAY macro to display STR array contents
                     MOV AH, 4CH                         ; terminate the program
                     INT 21H
      CODE ENDS                                           ; end of code segment
      END START                                            ; end of program

Output:

D:\MASM> Masm 7a.asm;
D:\MASM> Link 7a.obj;

D:\MASM> TD 7a.exe
Press F7 to trace the program (line by line execution).

0 comments: