Write and execute an alp to 8086 Microprocessor to reverse the given string and verify whether it is a palindrome.

Aim:

To write and execute an ALP to 8086 processor to reverse the given string and verify whether it is a palindrome.

Tools:

PC installed with MASM 6.11

Program:

.MODEL SMALL
.STACK 45H
ASSUME CS : CODE, DS : DATA
DATA SEGMENT
CR EQU 0DH
LF EQU 0AH
INS DB 40 DUP(0)
RES DB 40 DUP(0)
MSG1 DB 'ENTER THE STRING.INPUT STRING = ','$'
MSG2 DB CR,LF,'REVERSE OF STRING = ','$'
MSG3 DB CR,LF,'INPUT STRING IS PALINDROME','$'
MSG4 DB CR,LF,'INPUT STRING IS NOT A PALINDROME','$'
DATA ENDS
DISP MACRO MSG
MOV AH, 09H
MOV DX, OFFSET MSG
INT 21H
ENDM
CODE SEGMENT
START : MOV AX, DATA
    MOV DS,AX
    MOV SI,OFFSET INS
    MOV DI,OFFSET RES
    DISP MSG1
    MOV CX,00H
RDCHAR : MOV AH, 01H
    INT 21H
    CMP AL, CR
    JE AHEAD
    MOV [SI],AL
    INC SI
    INC CX
    JMP RDCHAR
AHEAD :    MOV BX, CX
REVERSE : DEC SI
     MOV AL, [SI]
     MOV [DI], AL
     INC DI
     LOOP REVERSE
     MOV AL, '$'
     MOV [DI], AL
     DISP MSG2
     DISP RES
     MOV SI, OFFSET INS
     MOV DI, OFFSET RES
     MOV CX, BX
CHECK :    MOV AL, [SI]
    CMP AL, [DI]
    JNE FALSE
    INC SI
    INC DI
    LOOP CHECK
    DISP MSG3
    JMP EXIT
FALSE : DISP MSG4
EXIT : INT 03H
CODE ENDS
END START
END

Result:

Input:

STR1 DB 01H, 02H, 03H, 04H

Output:

Strring reversal = 04Hh.03H, 02H.01H

Viva-voce questions:

1. Which instruction is used for indicating the direction for string operations?
2. What is a linker?
3. How an XCHG instruction works?
4. What is the role of REP?
5. What is the difference between base address and offset address of a word?