.model small
.data
string1 db 10 dup(' '), '$'
endl db 0dh, 0ah, '$'
.code
main proc
mov ax, @data
mov ds, ax
lea si, string1
mov ah, 1
READ_NEXT:
int 21h
cmp al, 13
je NEXT
mov [si], al
inc si
jmp READ_NEXT
NEXT:
mov al, '$'
mov [si], al
dec si
lea dx, endl
mov ah, 9
int 21h
lea di, string1
BEG:
mov bx, [di]
mov bp, [si]
mov [di], bp
mov [si], bx
dec si
inc di
cmp di, si
jl BEG
lea dx, string1
int 21h
lea dx, endl
int 21h
mov ah, 4ch
int 21h
main endp
end main
3 replies to this topic
#1
Posted 14 December 2010 - 01:31 PM
There are many examples for reversing a string in assembler on the net but I couldn't find any which only one string is used. So I decided to write myself one. And below is what I've created. The only problem is that it doesn't work. It reverses a part of the string a adds some characters at its end. Why is that? I've tried turbo debugging it but I cannot understand where actually string1 is visualised. Thank you in advance!
|
|
|
#2
Posted 14 December 2010 - 06:00 PM
At the area where it is:
BEG: mov bx, [di] mov bp, [si] mov [di], bp mov [si], bx dec si inc di cmp di, si jl BEGwould it work if you use 'al' and 'ah', instead of 'bx' and 'bp'?
Edited by dargueta, 14 December 2010 - 10:10 PM.
#3
Posted 14 December 2010 - 10:11 PM
Ooh, dude...don't use BP like that. You could cause some serious stack issues if you pass arguments using the stack, especially with external functions. RR is right, though.
sudo rm -rf /
#4
Posted 15 December 2010 - 01:17 AM
Thanks for the quick response!
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account

Back to top









