I need to write a program where the user input their name, the program will tell them 'Hello,' and then show the user's name backwards.

This is what I have:

INCLUDE Irvine32.inc

.data
pleaseEnter BYTE 'Please enter your name: ', 0
StringName BYTE 30 DUP(0)
yourName BYTE 'Hello, ', 0
StringReversed BYTE 30 DUP(0)
reverseName BYTE 'Here is your name backwards: ', 0
StringSize = ($ - StringReversed) - 1

.code
main PROC

mov edx, OFFSET pleaseEnter
call WriteString 

mov edx, OFFSET StringName 
mov ecx, SIZEOF StringName - 1

call ReadString
call CRLF
mov edx, OFFSET yourName

call WriteString
mov edx, OFFSET Stringname

call WriteString
call CRLF
call CRLF

mov edx, OFFSET reverseName
call WriteString 

mov ecx, StringSize
mov esi, 0

L1:	movzx eax, StringName[esi]
	push eax
	inc esi
	Loop L1

mov ecx, StringSize
mov esi, 0

L2:	pop eax
	mov StringReversed[esi], al
	inc esi
	Loop L2

mov edx,OFFSET StringName
call WriteString
call CRLF

	exit
main ENDP
END main

Everything works, except where it should reverse the name.
I've played around with the program several times, but it either ends up where the name is shown normally, with the 'Here is your name backwards: ' written backwards, with the space after that statement kept blank, among other problems.

I know it is a simple overall mistake, but I keep missing it.

Any advice?
I'm more used to C#, so it confuses me.

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...

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.

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:
and there are even other ways to do it also...

Sorry.
I'll be sure to keep that in mind from now on though.
So that's one less person, yes?

The only example I had to work with was from the book, for a string that was already within the program.
>_<

Thank you for explaining.
Makes more sense now.
I'll be sure to keep practicing so that I can understand more.
^-^

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.