0% found this document useful (0 votes)
82 views15 pages

LAB - 7 - R - AKASH - 20BCE1501 - Template

The document describes 4 assembly language programs to perform string handling operations using INT 21H: 1. Display a given string 2. Display the length of a given string 3. Reverse a given string 4. Check if a given string is a palindrome It provides the algorithms, sample code, input/output, and manual verification for each program. The goal is to learn basic string handling and using INT 21H in assembly language.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
82 views15 pages

LAB - 7 - R - AKASH - 20BCE1501 - Template

The document describes 4 assembly language programs to perform string handling operations using INT 21H: 1. Display a given string 2. Display the length of a given string 3. Reverse a given string 4. Check if a given string is a palindrome It provides the algorithms, sample code, input/output, and manual verification for each program. The goal is to learn basic string handling and using INT 21H in assembly language.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

Register No.

: 20BCE1501 Name: Akash R

Date: 08.03.2022 Exp.7 String handling and INT 21H

Aim:

1. To write an assembly language program to display the given String


2. To write an assembly language program to display the length of the
String.
3. To write an assembly language program to reverse the given String
4. To write an assembly language program to find whether a given String is
Palindrome or not.

Tool Used:

Assembler - MASM 611

Algorithm:

1] Display name:

Step 1 – START

Step 2 – Inside data segment store the String by ending it with “$”.

Step 3 – Write the code in code segment

Step 4 – Load effective address of the String into DX register

Step 5 – Move 09H to AH

Step 6 – Call INT 21H for printing the string

Step 7 – Move 4CH to AH

Step 8 – Call INT 21H for printing the status of program execution

Step 9 – HLT the program

Step 10 – END the code and program


Register No.: 20BCE1501 Name: Akash R

2] Length of String:
Step 1 – START

Step 2 – Inside data segment store the String by ending it with “$”.

Step 3 – Write the code in code segment

Step 4 – Write a loop statement for counting the characters

Step 5 – Check whether the character equals to “$” each time, once its equal
quit the loop.

Step 6 – Move count to dx register and add 30h to it

Step 7 – Print count by moving 02H to AH register and calling INT 21H

Step 8 – Load effective address of the String into DX register

Step 9 – Move 09H to AH

Step 10 – Call INT 21H for printing the string

Step 11 – Move 4CH to AH

Step 12 – Call INT 21H for printing the status of program execution

Step 13 – HLT the program

Step 14 – END the code and program

3] Reverse the String:


Step 1 – START

Step 2 – Inside data segment store the String by ending it with “$”.

Step 3 – Write the code in code segment

Step 4 – Write a loop statement for reversing the characters

Step 5 – After taking the character from last one by one store them in any
locations like 2000H and consecutive locations.
Register No.: 20BCE1501 Name: Akash R

Step 6 – Load address (ex. 2000H) of the reversed String into DX register

Step 7 – Move 09H to AH

Step 8 – Call INT 21H for printing the string

Step 9 – Move 4CH to AH

Step 10 – Call INT 21H for printing the status of program execution

Step 11 – HLT the program

Step 12 – END the code and program

4] Check Palindrome:
Step 1 – START

Step 2 – Inside data segment store the String by ending it with “$”.

Step 3 – Write the code in code segment

Step 4 – Write a loop statement for reversing the characters

Step 5 – After taking the character from last one by one check them with the
character taken from front and count how many time they are equal and store
the count in bx.

Step 6 – If the count is equal to length of the string print “Palindrome”.

Step 7 – If not print “Not Palindrome”.

Step 8 – Call INT 21H for printing the string

Step 9 – Move 4CH to AH

Step 10 – Call INT 21H for printing the status of program execution

Step 11 – HLT the program

Step 12 – END the code and program


Register No.: 20BCE1501 Name: Akash R

Program:

1] Display name:

dispname.asm:

DATA SEGMENT

MSG DB "AKASH", "$"

DATA ENDS

CODE SEGMENT

ASSUME CS:CODE, DS:DATA

START:

MOV AX, DATA

MOV DS, AX

MOV AX, 00H

LEA DX, MSG

MOV AH, 09H

INT 21h

MOV AH, 4CH

INT 21h

HLT

CODE ENDS

END START
Register No.: 20BCE1501 Name: Akash R

2] Length of String:
lenstr.asm:

DATA SEGMENT

MSG1 DB "AKASH", "$"

MSG2 DB "LENGTH OF THE STRING IS ", "$"

DATA ENDS

CODE SEGMENT

ASSUME CS:CODE, DS:DATA

START:

MOV AX, DATA

MOV DS, AX

MOV AX, 00H

LEA SI, MSG1

MOV CX, 00H

MOV AL, "$"

RPT: MOV AH, [SI]

CMP AL, AH

JE EXIT

INC CX

INC SI

JMP RPT

EXIT: LEA DX, MSG2

MOV AH, 09H

INT 21H
Register No.: 20BCE1501 Name: Akash R

MOV DX, 00H

MOV DL, CL

ADD DL, 30H

MOV AH, 02H

INT 21h

MOV AH, 4CH

INT 21H

HLT

CODE ENDS

END START

3] Reverse the String:


rev.asm:

DATA SEGMENT

MSG1 DB "AKASH", "$"

DATA ENDS

CODE SEGMENT

ASSUME CS:CODE, DS:DATA

START:

MOV AX, DATA

MOV DS, AX

MOV AX, 00H

MOV BX, 00H

LEA SI, MSG1


Register No.: 20BCE1501 Name: Akash R

LEA DI, MSG1

MOV CX, 00H

MOV AL, "$"

RPT1: MOV AH, [SI]

CMP AL, AH

JE EXIT

INC CL

INC SI

JMP RPT1

EXIT:

LEA DI, MSG1

ADD DI, CX

MOV BX, 2000H

RPT2: DEC DI

MOV AL, [DI]

MOV [BX], AL

INC BX

DEC CL

CMP CL, 00H

JE EXIT1

JMP RPT2

EXIT1: MOV [BX], "$"

MOV DX, 2000H

MOV AH, 09H


Register No.: 20BCE1501 Name: Akash R

INT 21H

MOV AH, 4CH

INT 21H

HLT

CODE ENDS

END START

4] Check Palindrome:
palin.asm:

DATA SEGMENT

MSG1 DB "AKASH", "$"

MSG2 DB "THE GIVEN STRING IS PALINDROME.", "$"

MSG3 DB "THE GIVEN STRING IS NOT PALINDROME.", "$"

DATA ENDS

CODE SEGMENT

ASSUME CS:CODE, DS:DATA

START:

MOV AX, DATA

MOV DS, AX

MOV AX, 00H

MOV BX, 00H

LEA SI, MSG1

LEA DI, MSG1

MOV CX, 00H


Register No.: 20BCE1501 Name: Akash R

MOV AL, "$"

RPT1: MOV AH, [SI]

CMP AL, AH

JE EXIT

INC CL

INC SI

JMP RPT1

EXIT:

LEA SI, MSG1

LEA DI, MSG1

ADD DI, CX

MOV BH, CL

RPT2: DEC DI

MOV AH, [SI]

MOV AL, [DI]

CMP AL, AH

JE INCR

JMP CONT

INCR: INC BL

CONT: INC SI

DEC CL

CMP CL, 00H

JE DIS

JMP RPT2
Register No.: 20BCE1501 Name: Akash R

DIS:

CMP BL, BH

JE EXIT1

JMP EXIT2

EXIT1: LEA DX, MSG2

MOV AH, 09H

INT 21H

JMP HALT

EXIT2: LEA DX, MSG3

MOV AH, 09H

INT 21H

HALT: MOV AH, 4CH

INT 21H

HLT

CODE ENDS

END START

Sample Input:

1] Display name:

MSG = “AKASH”, “$”

2] Length of String:
MSG1 = “AKASH”, “$”

MSG1 = “LENGTH OF THE STRING IS ”, “$”


Register No.: 20BCE1501 Name: Akash R

3] Reverse the String:


MSG1 = “AKASH”, “$”

4] Check Palindrome:
MSG1 = "MADAM", "$"

or

MSG1 = “AKASH”, “$”

Sample Output:

1] Display name:

AKASH

Program terminated noramlly

2] Length of String:
LENGTH OF THE STRING IS 5

Program terminated noramlly

3] Reverse the String:


HSAKA

4] Check Palindrome:
THE GIVEN STRING IS PALINDROME.

Or
Register No.: 20BCE1501 Name: Akash R

THE GIVEN STRING IS NOT PALINDROME.

Manual Verification:

1] Display name:

MSG = “AKASH”, “$”

AKASH

2] Length of String:
MSG1 = “AKASH”, “$”

Length = 5

3] Reverse the String:


MSG1 = “AKASH”, “$”

If we reverse it becomes,

HSAKA

4] Check Palindrome:
MSG1 = “AKASH”, “$”

HSAKA not same, so not a palindrome

Or

MSG1 = “MADAM”, “$”

MADAM same, so palindrome


Register No.: 20BCE1501 Name: Akash R

Register/ Memory Contents for I/O:

1] Display name:

2] Length of String:
Register No.: 20BCE1501 Name: Akash R

3] Reverse the String:

4] Check Palindrome:
Register No.: 20BCE1501 Name: Akash R

Snapshot of the Output:

1] Display name:

2] Length of String:

3] Reverse the String:

4] Check Palindrome:
MSG1 = AKASH

MSG1 = MADAM

Result:

From the above experiment I have learned to write basic assembly language
codes for String handling and INT 21H.

You might also like