News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

length of a string

Started by stapper, March 20, 2010, 11:01:50 AM

Previous topic - Next topic

stapper

Hi, Iam new in assembler and a trying to learn ASM and have a basic Question.

.Data
sztext1   DB "text1",0
sztext2   DB "texttwo",0


labels DD offset sztext1
DD offset sztext2
.
.
mov ecx,0
mov eax,labels[ecx*4]

I want to know the length from the were eax is pointing to. In need it for use with TextOut

thanks

BogdanOntanu

#1
Quote from: stapper on March 20, 2010, 11:01:50 AM
Hi, Iam new in assembler and a trying to learn ASM and have a basic Question.

.Data
sztext1   DB "text1",0
sztext2   DB "texttwo",0


labels DD offset sztext1
DD offset sztext2
.
.
mov ecx,0
mov eax,labels[ecx*4]

I want to know the length from the were eax is pointing to. In need it for use with TextOut

thanks

Use one of the StrLen kind of functions available in MASM32  (or write your own for learning).

As a conceptual example:

mov ecx,0
mov eax,labels[ecx*4]
invoke StrLen, eax
; now eax contains the length of the string, but you have lost the pointer to the string


However beware that normal functions will return the result in EAX register (in this case the length). In your case this will / would overwrite your EAX that contains the pointer to your string.

In order to avoid such problems it is better to keep the string pointer into another register like this:

mov ecx,0
mov ebx,labels[ecx*4]
invoke StrLen, ebx


In this example EAX contains the length of the string, and EBX still contains the pointer to the string
because by convention functions do not change EBX,ESI and EDI.

In order to use StrLen you might need to include the MASM32 inc file and libs if you did not do that already.

Ambition is a lame excuse for the ones not brave enough to be lazy.
http://www.oby.ro

Farabi

There are 2 ways to determined string length.
First you scan the memory until it found byte that have value 0.
Second, use "sizeof" command, but it only works for defined string.
Those who had universe knowledges can control the world by a micro processor.
http://www.wix.com/farabio/firstpage

"Etos siperi elegi"

stapper

It works.

Thanks to everybody.


jj2007