Assembly Language for Beginners

(Jeff_L) #1

1.17. MORE ABOUT STRINGS


mov edx, DWORD PTR _str$[esp-4] ; EDX -> pointer to the string
mov eax, edx ; move to EAX
$LL2@strlen:
mov cl, BYTE PTR [eax] ; CL = *EAX
inc eax ; EAX++
test cl, cl ; CL==0?
jne SHORT $LL2@strlen ; no, continue loop
sub eax, edx ; calculate pointers difference
dec eax ; decrement EAX
ret 0
_strlen ENDP


Now it is all simpler. Needless to say, the compiler could use registers with such efficiency only in small
functions with a few local variables.


INC/DEC—areincrement/decrementinstructions, in other words: add or subtract 1 to/from a variable.

Free download pdf