Reputation: 57
What's wrong with this code? I am expecting this program to reverse the string and display it.
;String reverse (Problem is it is displaying any output)
.model small
.stack 100h
.data
text1 db 'HELLO WORLD $'
text2 db 13 dup(?)
count dw 13
.code
main proc
mov ax, @data
mov ds,ax
mov es,ax
mov cx,count
mov si,0
mov di,0
add di,count
dec di
again: mov al,text1[si]
mov text2[di],al
inc si
dec di
loop again
lea dx,text2
mov ah,9
int 21h
mov ah,4ch
int 21h
main endp
end main
Upvotes: 1
Views: 51
Reputation: 39166
When reversing (and hoping to display the result!) you should not allow for the original $ character to be moved to the beginning of the result.
Setting count to 12 in stead of 13 should do the trick provided you change the definition of text2:
text2 db 12 dup(?), "$"
Upvotes: 3