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
Blog Archive
-
▼
2014
(37)
-
▼
February
(12)
- a program to create a file (input file) and to del...
- Read a pair of input co-ordinates in BCD and move ...
- Write a program to simulate a Decimal Up-counter t...
- Read the current time from the system and display ...
- Compute nCr using recursive procedure. Assume that...
- Read your name from the keyboard and display it at...
- Read two strings, store them in locations STR1 and...
- Reverse a given string and check whether it is a p...
- Read an alphanumeric character and display its equ...
- Sort a given set of ‘n’ numbers in ascending order...
- Write two ALP modules stored in two different file...
- Search a key element in a list of ‘n’ 16-bit numbe...
-
▼
February
(12)
Friday, February 21, 2014
ASSUME DS:DATA, CS:CODE
DATA SEGMENT ; start of data
segment
STR DB 25 DUP(' '),'$' ; reserve 25
bytes blank memory location for STR array(to store
;user entered
string)
RSTR DB 25 DUP(' '),'$' ; reserve 25
bytes blank memory location for RSTR array( to
;store the
reversed string)
COUNT DB ? ; a variable is declared to store the total no.
characters present in
;user
entered string.
MSG1 DB 0DH, 0AH, 'ENTER A STRING :', '$'
MSG2 DB 0DH, 0AH, 'REVERSE OF THE STRING IS
:', '$'
MSG3 DB 0DH, 0AH, 'ENTERED STRING IS PALINDROME', '$'
MSG4 DB 0DH, 0AH, 'ENTERED STRING IS NOT PALINDROME', '$'
DATA ENDS ; end
of data segment
DISPLAY
MACRO MSG ; DISPLAY macro
definition starts here ( used to display the
;various messages
on the screen)
MOV
DX, OFFSET MSG
MOV AH, 09H ; use service no.
09H to display the message on the screen
INT 21H ; using DOS
interrupt 21H
ENDM
CODE SEGMENT ; end of code
segment
START :
MOV AX, DATA
MOV DS,
AX ; initializing data segment.
MOV ES,
AX ; initializing
extra segment.
XOR CX, CX ; clear
CX register content
MOV SI, OFFSET
STR
; STR array’s 1st
memory location is pointed by SI (offset
addr)
DISPLAY
MSG1 ;
macro is invoked to display the 1st message MSG1
BACK: MOV AH, 01H ; using 01H service no with DOS interrupt
21H, read
INT 21H ; a character from keyboard.
CMP AL, 0DH ;compare
the user entered character with the enter
key (ascii)
JE STOP ; if it is equal to enter key, then go to STOP,
& terminate the read process.
MOV [SI], AL ; otherwise store the character in STR
array
INC SI ; after copying a character to the STR
array, memory pointer is
; incremented by
1, to point to the next memory location.
INC CL ; after
reading a character, counter value in CL is incremented by 1
; to indicate the length of the
string.
JMP BACK ; go to BACK and
read the next character from keyboard.
STOP: MOV COUNT, CL ; store the
length of the input string in COUNT variable.
DEC SI
; SI points to the last character of the input string in
STR array.
MOV DI, OFFSET
RSTR ; DI points to the
1st location of RSTR array (store the reversed string)
AGAIN: MOV AL, [SI]
MOV [DI], AL ; generates
the reverse of STR array contents and stores in RSTR
INC DI ; DI points the next position in RSTR
array.
DEC SI ; SI points to the previous character in
STR array.
LOOP AGAIN ; if count (length) in CL is not zero, then jump
to AGAIN
DISPLAY MSG2 ; macro is
invoked to display the message MSG2
DISPLAY
RSTR ;
invoke the macro to
print the reversed string, which is in RSTR
MOV CL, COUNT ;
length is again moved to CL
MOV
SI, OFFSET STR
; SI points to
the 1st character of the string in STR
MOV
DI, OFFSET RSTR ; DI points to
the 1st character of the reversed string in RSTR
CLD ;clear direction flag for auto increment
mode
REPE CMPSB ; compare the
string bytes pointed by SI and DI
JNE NEXT ; if strings are not equal jump to label
NEXT
DISPLAY MSG3 ; otherwise invoke
the macro to display the message MSG3
JMP
EXIT ; jump to label
EXIT to terminate the program
NEXT:
DISPLAY MSG4 ;
invoke the macro to display the message MSG4
EXIT: MOV AH, 4CH ; terminate the
program
INT 21H
CODE ENDS ; end of code
segment.
END
START ; end of program
Output:
D:\MASM>
Masm 5a.asm;
D:\MASM>
Link 5a.obj;
D:\MASM>
5a.exe

D:\MASM>
5a.exe

OR
D:\MASM>
TD 5a.exe
Then press F7 to trace the program (line by line execution).
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment
You are very Important to Us...
STAY TUNE...