string reverse.. help..

the prOgram is abOut inputting a string and then the result will be its reversed string..

for example: insecure
the result must be "erucesni"

i have my cOde belOw..

help me please..

[color=Red].MODEL SMALL
.STACK 100h

MaxChars DB 10
NumChars DB 0
InputBuffer DB 'xxxx xxxx ' ; Room for 9 chars + CR
TextNumChars DB 'x',13,10,'$'

StringPrompt DB 'Type a line of text: $'
DisplayReverse DB 13,10,'Result: $',13,10

mov ax,@data
mov ds,ax
mov dx,OFFSET StringPrompt
mov ah,9
int 21h

mov dx,OFFSET MaxChars
mov ah,10
int 21h

mov dx,OFFSET DisplayReverse
mov ah,9
int 21h

mov si,OFFSET InputBuffer ; InputBuffer will

contain the entered characters

mov ah,4ch ; DOS terminate

program routine
mov al,0
int 21h

END start[/color]


that's it..

help me please..



  • I'm really tired and only spent 5 minutes on this... but I think I didn't make any terrible errors...

    ; assuming SI is already set to point to InputBuffer....
    cmp al,13 ; search for end of string
    jne findEnd
    mov di,si
    mov si,offset InputBuffer
    push di ; location of string terminator
    dec di ; minus 1 == last byte of string
    mov al,[si]
    mov ah,[di]
    mov [di],al
    mov [si],ah
    inc si
    dec di
    cmp si,di
    jb swapLoop
    pop di
    mov [di],'$' ; change CR to '$' for printing
    mov dx,offset InputBuffer
    mov ah,9
    int 21h
    I hope this isn't homework... at least the post is really old...
Sign In or Register to comment.

Howdy, Stranger!

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


In this Discussion