DATA SEGMENT
S DB 'HELLO','$'
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE, DS:DATA
START:
MOV AX, DATA ; Load data segment address
MOV DS, AX ; Move it to DS
LEA SI, S ; Load address of string S into SI
MOV AH, 09H ; Function 09h: display string till '$'
INT 21H
; Find length of the string
LEA SI, S
MOV CX, 0
FIND_LEN:
MOV AL, [SI]
CMP AL, '$'
JZ REV
INC SI
INC CX
JMP FIND_LEN
REV:
DEC SI ; SI now points to last character before '$'
REVERSE_STRING:
MOV AH, 02H ; Function 02h: display character in DL
MOV DL, [SI]
INT 21H
DEC SI
LOOP REVERSE_STRING
MOV AH, 4CH ; Exit program
INT 21H
CODE ENDS
END START