You are on page 1of 5

CSE2006 LAB L45+46

EX-7 STRING INSTRUCTIONS

Shreya Sivakumar
20BCE1794

AIM: Write a program in 8086 microprocessor to add two arrays of


hexadecimal numbers using string instructions. And to find whethere a given
string is palindrome or not using string instructions

TOOLS REQUIRED: Assembler - MASM 611 PC with DOS and Debug


program

PROCEDURE: We write an assembly language program in 8086


microprocessor to add two array and to check if a string is palindrome and
display the output

ALGORITHM:
(Adding Arrays)
• In the data segment, initialise both the arrays
• In extra segment store the variable z=result
• Initialise data segment
• Count register= number of elements in array
• Add nth number in 1st array with the nth number in the 2nd array
• Store results
• Decrement the count
• Jump to the display when the result is not equal to 0
• Else terminate the program
• Code ends

(Palindrome String)

• Define BLOCK1 that needs to be reversed and create variable LEN


• Create string ‘IS PALINDROME’ and ‘IS NOT PALINDROME’ and
assign them to variables
• Initialise data and extra segments
• SI= Address of BLOCK1, DI= Address of BLOCK2
• Compare the value stored at the address
• Increment the pointer, SI
• Decrements the pointer, DI
• Compare again the value stored at SI and DI
• Repeat the steps until SI<=DI
• Display MSG1
• Else skip display MSG2
• Stop

CODES:

1. STRING ADDITION:
DATA SEGMENT
A DB 35H,36H,37H,38H
B DB 45H,46H,47H,48H
DATA ENDS

EXTRA SEGMENT
Z DB ?
EXTRA ENDS

CODE SEGMENT
START:
MOV AX,DATA
MOV DS,AX
MOV ES,AX
MOV BX,0000H
MOV CL,04H
MOV DI, OFFSET Z

UP:
MOV AL, A[BX]
ADD AL, B[BX]
INC BX
STOSB
DEC CL
JNZ UP

INT 03H
CODE ENDS
END START

OUTPUT:

2. PALINDROME:
DATA SEGMENT

BLOCK1 DB 'DAD'
MSG1 DB "IS PALINDROME $"
MSG2 DB "IS NOT PALINDROME $"
PAL DB 00H

DATA ENDS

PRINT MACRO MSG

MOV AH,09H
LEA DX,MSG
INT 21H
INT 3H

ENDM

EXTRA SEGMENT

BLOCK2 DB 9 DUP(?)
EXTRA ENDS

CODE SEGMENT
ASSUME CS:CODE,DS:DATA,ES:EXTRA
START: MOV AX,DATA
MOV DS,AX
MOV AX,EXTRA
MOV ES,AX

LEA SI,BLOCK1
LEA DI,BLOCK2+8
MOV CX,00009H

BACK: CLD
LODSB
STD
STOSB

LOOP BACK
LEA SI,BLOCK1
LEA DI,BLOCK2
MOV CX,0009H
CLD
REPZ CMPSB

JNZ SKIP
PRINT MSG1
SKIP: PRINT MSG2

CODE ENDS
END START
OUTPUT:
(String=”DAD”)

(STRING= “SHREY”)

RESULT: We have performed addition of two arrays using instruction of


strings and finiding if a string is a palindrome or not following the
algorithm and using 8086 progtams in DosBox application.

You might also like