Categories
- 4th semester (27)
- 5th semester (3)
- ADA (13)
- Assembly Level Language (12)
- BE (45)
- C Language Programming (5)
- C language (20)
- C++ Language (5)
- CCP Lab programing (3)
- Computer Programming Lab (3)
- DAA Lab Programming (13)
- Data Structure and C++ laboratory Program (6)
- Data Structure and C++ labotary Program (5)
- Design and Analysis of algorithm (14)
- First Year (5)
- MASM (12)
- Microprocessor (12)
- Microprocessor lab program (12)
- System Software & OS Laboratory (5)
- Unix program (4)
- bachelor of engineering (30)
- basic (1)
- basic mathematics (2)
- beginners (10)
- c++ program (9)
- calculations (7)
- computer science (30)
- downloadable (5)
- engineering syllabus (4)
- simple program (6)
Trend Posts
Blogger news
Author
Followers
Showing posts with label character. Show all posts
Showing posts with label character. Show all posts
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
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).
Subscribe to:
Posts (Atom)