Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

reverse string help...

zhinokinzhinokin Member Posts: 3
can you give me some codes that would reverse a string ..i have my code but its not complete in the reverse_loop function....will you please help me to solve this one...or give me the riht code to reverse a string....


i would greatly appreciate your help...


[code]
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:$"

[/code]

Comments

  • AsmGuru62AsmGuru62 Member Posts: 6,519
    [color=Blue]
    Here is how to reverse:
    [/color]
    [code]
    ;
    ; You need to figure these parameters
    ; Maybe count symbols entered by user?..
    ;
    mov si,

    mov di,


    .Reversing:
    ;
    ; Check if more characters needs reversing
    ;
    cmp si, di
    jae .NoMoreChars2Reverse
    ;
    ; Aha! We have to get characters at SI and DI and
    ; Store them back, but reversed!
    ;
    mov al, [si]
    mov dl, [di]

    mov [di], al
    mov [si], dl
    ;
    ; Now, move one pointer forward and another one backward
    ;
    inc si
    dec di
    ;
    ; Go back and check if we have more to reverse
    ;
    jmp .Reversing

    .NoMoreChars2Reverse:
    ;
    ; We done with reversing!
    ; ...
    [/code]
  • zhinokinzhinokin Member Posts: 3
    will you please help me apply your code to my code...

    so that i can get it perfectly...i tried it but there's an error...

    maybe i have not completely comply some codes you have given....

    please help....



  • AsmGuru62AsmGuru62 Member Posts: 6,519
    : will you please help me apply your code to my code...
    :
    : so that i can get it perfectly...i tried it but there's an error...
    :
    : maybe i have not completely comply some codes you have given....
    :
    : please help....
    :
    :
    :
    :
    [color=Blue]Please post your code (with my code merged in) here, so I can see it. If you use TASM - maybe, remove the dots on labels.[/color]
Sign In or Register to comment.