I have an assembly program which writes the length of a string in ax register but I am a little bit confused about some instructions.
include \masm32\include64\masm64rt.inc
.data
string db "mama", 0 ; so here I declared a string "mama". What happens in memory?
.code
main proc
xor ax, ax ; here I initialize ax with 0.
lea rsi, string ; here, I move in rsi register the adress of string, right? But how the string is stored in memory? Now in rsi I have the adress of the first char "m" of "mama" string?
@@: ; this sign creates an anonymous label
cmp byte ptr [rsi], 0 ; so this says compare 0 with with 1 byte found at the adress pointed to by rsi, right? But I still don't get it. Why 1 byte? rsi is pointing to the first char or to the whole string?
jz @F ; jump if zero to the nearest @@ (forward)
inc ax ; so now i'm pointing to the first character so ax=1
inc rsi ; here what happen? The pointer is incremented to point to the second char from string?
jmp @B ; jump to the nearest @@ (backward)
@@:
invoke ExitProcess, 0 ; invoke ExitProcess API
ret
main endp
end
My confusion is that I'm not sure if I think about how this program works in a right way. Am I thinking this correctly?