Blogger news

Followers

Friday, February 21, 2014


ASSUME DS: DATA, CS: CODE
DATA SEGMENT                                                               ; start of data segment
CHAR DB  ?                                                 ;Byte variable is not initialized, and used later.
MSG1 DB 0DH, 0AH, 'ENTER A CHARECTER : ','$'      ;MSG1 array contains the message
MSG2 DB 0DH, 0AH, 'ASCII EQUIVALENT IS : ','$'     ;MSG2 array contains the message.  
DATA ENDS                                                                         ; end of data segment.
                
DISPLAY  MACRO  ASCI                                                    ; Macro definition starts here
MOV DL, ASCI                                                                              ; Ascii code to be displayed is moved to DL 
AND DL, 0F0H                                                        ; Mask the lower nibble stored in DL
MOV  CL, 04H                                                          ; counter to rotate 4 times.
ROR DL, CL                                                              ; Rotate DL contents right 4 bit positions
CMP DL, 09H                                                                        ; compare the number stored in DL with 09
JBE NEXT                                                                   ; if the number is <= 9 then go to NEXT location
; and add 30H to that number
ADD DL, 07H                                                                        ; otherwise, first add 07H to that number and
NEXT :  ADD DL,30H                                                ; then add 30H to that number
MOV AH, 02H                                                           ; service number to display a character on the
; monitor ( upper digit of the ASCII code is displayed)
INT 21H                                                                     ; using DOS interrupt
MOV DL, ASCI                                                                              ; Ascii code to be displayed is moved to DL 
AND DL, 0FH                                                           ; Mask the higher nibble stored in DL
CMP DL, 09H                                                                        ;compare the number stored in DL with 09
JBE AGAIN                                                                  ;if the number is <= 9 then go to AGAIN location
                                                                        ; and add 30H to that number, & then display
ADD DL, 07H                                                                        ; otherwise, first add 07H to that number and
AGAIN:    ADD DL, 30H                                             ; then add 30H to that number & then display.
MOV AH, 02H                                                           ; service number to display a character on the
; monitor ( lower digit of the ASCII code is displayed)
INT 21H                                                                     ; using DOS interrupt 21H
ENDM                                                                        ; End of Macro definition               
CODE SEGMENT                                                   ; start of code segment
START:
       MOV AX, DATA
       MOV DS, AX                                         ; initialize data segment
       MOV DX, OFFSET MSG1                   ; address of string to be display
       MOV AH, 09H                                                    ; service number to display string
       INT 21H                                                              ; MSG1 is printed on screen
       MOV AH, 01H                                                    ;service number to read a character from keyboard
       INT 21H                                                              ; DOS interrupt is invoked, so that a character is read
; from the keyboard.
       MOV CHAR, AL                                                            ; user entered character’s ASCII code is moved
; to CHAR variable
       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, 39H                                                    ; Number of rows; Lower right row              
       MOV DL, 79H                                                    ; Number of columns; lower right column     
       INT 10H                                                              ; BIOS interrupt to clear the screen is invoked.

       MOV AH, 02H                                                   ; service number to set the cursor
       MOV BH, 00                                                       ; Page number
       MOV DH, 09H                                                    ; store row number in DH
       MOV DL, 04H                                                    ; store the column number in DL register
       INT 10H                                                              ; BIOS interrupt to set the cursor is invoked.
       MOV DX, OFFSET MSG2                               ; store the address of string to display in DX
       MOV AH, 09H
       INT 21H                                                              ; DOS interrupt to display the string MSG2
       DISPLAY  CHAR                                                ; invoke DISPLAY macro to print the ASCII code
       MOV AH,4CH                                                    ; service number to terminate the program
       INT 21H                                                              ; call the interrupt
       CODE ENDS                                                      ; end of code segment                                               
       END START                                                         ; end of program
Output:
D:\MASM> Masm 4a.asm;
D:\MASM> Link 4a.obj;
D:\MASM> 4a.exe
 

OR
D:\MASM> TD 4a.exe
Then press F7 to trace the program (line by line execution).  

0 comments: