I need to write a program that reverse the letters order. I wrote the following program but it doesn't work for me.
Please help me fix my program:
org 100h
jmp main
string db 'm', 'g', 'g', 'i', 'h', 's', 'f', 'g', 'm',0Dh,0Ah,'$'
main:
lea ax,string
push 9
push offset string
call reverse
lea ax,string
mov ah,0
int 16h
ret
reverse proc
push bp
mov bp,sp
sub sp,6;
len equ [bp + 6]
i equ [bp - 4]
temp equ [bp - 2]
mov ax,[bp+6]
mov len,ax
dec len
mov dx,len
mov i,ax
mov bx,[bp+4]
mov ax,i
for1:
mov si,i
mov cl, [bx+si]
mov dl, cl
mov di, ax
sub di, si
mov [bx+di],cl
mov cl,dl
mov [bx+si], cl
mov ax,len
mov cl,2
div cl
dec i
cmp i,ax
jge for1
mov sp,bp
pop bp
ret
reverse endp</code>
........................................ Uri.
You had some unnecessary code, and some wrong code. I made some changes to make it run, here it is (the comments explain the changes), copy-paste it on EMU8086 and run it :