could someone help me how to reverse a string in a86 ...the program will goes like this.user will input a string of 4 characters or less than 4 for ex..whin then it will output nihw..but if the user will input 5 or more than, for ex. whinz the output would be whinzznihw...

i have a code here but it has some error in reversing..

begin:
        call erase
        call display_remark
        call get_data
        call comparator

        int 20h

erase:
       mov ax,03h
       int 10h
       ret

display_remark:
        mov ah,09h
        lea dx,string_remarks
        int 21h
        ret

get_data:
        mov ah,0ah
        lea dx,store_string
        int 21h
        ret


comparator:
        mov bx,2
        Xor dx,dx
        Xor si,si
        Xor di,di
        Xor ax,ax
        mov si,b[store_password]
        mov cx,5

goto_end_string:
        mov al,b[si]
        mov ah,b[store_password + bx]	
        inc si,1
        inc bx,1
        loop goto_end_string	
        jmp reverse	

reverse:
        mov b[store_password + bx], ah	
        dec si,1
        dec bx,1	
        loop reverse

        mov ah,09h
        lea dx, string_reverse    
        int 21h
again:

	mov dx,offset msg
	mov ah, 9        
	int 21h
	mov ah, 1   
	int 21h
	mov char1,al	
	cmp al,'y'
	je begin
	cmp al,'Y'
	je begin
	int 21h
	ret 
        


msg db 0ah,0dh, "Try Again [y/n] : $"
char1 db ?

store_store db 10 dup()
string_remarks db 0d,0d,0d,0d,0d,0d,0d,0d,0d,0d,0d,0d,0d,    "Enter a string: $"
string_reverse db 0d,0d,0d,0d,0d,0d,0d,0d,0d,0d,0d,0d,0d,    "String in reverse order is: $"
XOR EDX,EDX
MOV ECX,length
reverse_loop:
MOV AL,[string_remarks+EDX]
MOV [string_reverse+ECX],AL
LOOP reverse_loop

I'm pretty sure that's what you mean. If you have probs with you memory then try length-1 in EDX or increase ECX or something like that. If it's not working at all than ask again an I'll try my code at home.

Greetings
Simon

i have try it ...but there's an error occur..

i'm just wondering is that could you give is an a86..

whatever...will you help me to solve this one...

can u share me your codes....

I forgot to increase EDX. Just add

INC EDX

at the end of the loop.

If this doesn't help then try to explain the bug in more detail or write me a PM.

i already try what you give but there's an error.

the error is bad index register...
in the reverse_loop function..

please help...to solve this one....

begin:
        call erase
        call get_input1
        call store_data1	
	
        call reverse

        int 20h

erase:
       mov ax,03h
       int 10h
       ret

get_input1:
        mov ah,09h
        lea dx,INPUT_strng1 
        int 21h
        ret

store_data1:
        mov ah,0ah
        lea dx,store_strng1
        int 21h
	ret

comp:
	xor dx,dx
	mov cx,length

reverse_loop:

	mov al,[store_strng1+dx]
	mov [string_reverse+cx],al
	loop reverse_loop
	inc dx	
	



display_back:

	mov dx,offset msg
	mov ah, 9        
	int 21h
	mov ah, 1   
	int 21h
	cmp al,'y'
	je begin
	jne exit


exit:
	mov ah, 4ch
	int 21h


msg db 0a,0d, "Try Again [y/n] : $"


INPUT_strng1 db 0d,0d,0d,0d,0d,0d,0d,0d,0d,0d,0d,0d,"Input a string: $"
store_strng1 db 10 dup()
length db equ 10
correct_remarks db 0a,0d,0d,0d,0d,0d,0d,0d,0d,0d,0d,0d,0d,"String in Reverse:$"

Than you can't use DX or CX for indexing. Use ESI or EDI instead.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.