This is a sample assembly language code for 8086 to print a string in reverse order
.model small
.STACK 100H
.DATA
MSG DB 'HELLO!$'
.CODE
MOV CL,0
AGAIN:
MOV DL,DS:[SI]
; MOV AH,2
; INT 21H
INC CL
INC SI
CMP DL,'$'
JNE AGAIN
DEC SI
DEC CL
REV:
DEC SI
MOV DL,DS:[SI]
MOV AH,2
INT 21H
DEC CL
CMP CL,0
JNE REV
.EXIT
END
It's output is !OLLEH . But if I write
MOV AH,2
INT 21H
in AGAIN level below MOV DL,DS:[SI] . I think answer should be HELLO!!OLLEH but it shows '=' character and previous output. Why does it happen?
Correction. Since you check for the "$" character only after outputting with the DOS function 02h, the screen should show:
It's just with DOS function 09h that it is impossible to write a "$" character.
It's possible to get semi-correct results because emu8086 initialized the registers in some default manner, but it's best to setup the registers manually before using them: