Error in a string reversal program in emu8086

Viewed 49

I tried a string reversal program, but emu8086 is showing me an error message

(12)offset calculation error

What is wrong with the line LEA DI,STR2+LEN-1 ?

DATA SEGMENT
STR1 DB 'HELLO'
LEN EQU $-STR1
STR2 DB 20 DUP(0)
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE, DS:DATA, ES:DATA
START: MOV AX,DATA
MOV DS,AX
MOV ES,AX
LEA SI,STR1
LEA DI,STR2+LEN-1
MOV CX,LEN
UP: CLD
LODSB
STD
STOSB
LOOP UP
MOV AH,4CH
INT 21H
CODE ENDS
END START
1 Answers

I'm not using emu8086, but the following will correct your line 12:

mov di, offset STR2 + LEN - 1

The shorter way to obtain an address is writing mov si, offset STR1 (uses 3 bytes) instead of lea si, STR1 (uses 4 bytes).


The loop ends with the direction flag still set!
It will always be a good idea to have the direction flag cleared before invoking any system function:

...
LOOP UP
CLD            ; Add this to clear direction flag
MOV AH,4CH     ; DOS.Terminate
INT 21H
...
Related