Few things, why do folks who use Irvine, not use the correct case for the function calls? There is no such function as CRLF, instead it is Crlf. I don't know how the Irvine users don't get errors when Assembling!
Put your 2 buffers in the uninitialized data section - .data?
StringSize - we don't need it, why? ReadString returns the size of the string it reads in.
.data
pleaseEnter BYTE 'Please enter your name: ', 0
yourName BYTE 'Hello, ', 0
reverseName BYTE 'Here is your name backwards: ', 0
.data?
StringName BYTE 30 DUP (?)
StringReversed BYTE 30 dup (?)
.code
main PROC
mov edx, OFFSET pleaseEnter
call WriteString
mov edx, OFFSET StringName
mov ecx, SIZEOF StringName - 1
call ReadString
mov ecx, eax ; <<<<<<<<<<<<<< save the string length
call Crlf
mov edx, OFFSET yourName
call WriteString
mov edx, OFFSET StringName
call WriteString
call Crlf
call Crlf
mov edx, OFFSET reverseName
call WriteString
lea esi, StringName
lea edi, StringReversed
dec ecx ; <<<<<<<<<<<<<< Decrease the counter
@@:
test ecx, ecx
js Done ; <<<<<<<<<<<<<< are we below zero?
mov al, byte ptr [esi + ecx] ; <<<<<<<<<<<<<< move the char in esi to al
mov byte ptr [edi], al ; <<<<<<<<<<<<<< now move into edi
inc edi ; <<<<<<<<<<<<<< increase pos of edi
dec ecx ; <<<<<<<<<<<<<< decrease our counter
jmp @B ; <<<<<<<<<<<<<< reverse next char
Done:
mov edx, offset StringReversed
call WriteString
call Crlf
call WaitMsg ; <<<<<<<<<<<<<< good to have so you can see results :)
exit
main ENDP
END main
There are other ways to do this. For instance, Irvine has a function called WriteChar which prints the char in al to console, so you can skip your Reversed buffer and the mov byte ptr [edi] stuff and do something like this instead:
lea esi, StringName
dec ecx
@@:
test ecx, ecx
js Done
mov al, byte ptr [esi + ecx]
call WriteChar
inc edi
dec ecx
jmp @B
Done:
call Crlf
call WaitMsg
exit
and there are even other ways to do it also...
GunnerInc
xor eax, eax
Team Colleague
79 posts since Jan 2011
Reputation Points: 38
Solved Threads: 13