I've written some 8086 assembly code to reverse a string. I'm relatively new to assembly so please bear with me.
The logic is that I define a string called 'str1'. I move this into the SI Register. Suppose string 'str1' is "Hello$", then I load the address of 'str1'+5 into SI. Now, I load an address, say 5000 into DI. And I load each character from SI into DI and everytime I increment SI and decrement SI till 5 times.
Here is the code
assume cs:code,ds:data
data segment
str db "Hello$"
data ends
code segment
start:
mov ax,data
mov ds,ax
cld
mov cx,5h
mov bx,5h
lea si,str
add si,5
mov di,5000h
l1:mov bx,[si]
mov [di],bx
dec si
inc di
loop l1
hlt
code ends
end
I get an absolute garbage value when I access location 5000. Plz help thanks
Your code is almost good, you only need an auxiliary string (if such thing is allowed) :