Professional Documents
Culture Documents
Shreya Sivakumar
20BCE1794
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)
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
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”)