News:

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

Array

Started by ragdog, March 28, 2010, 07:50:07 PM

Previous topic - Next topic

ragdog

Hi

I have on any source see for a long time an array
i dont now works this can you help me please?

.data

lpText    db "Test1","Test2",0
lpCap     db "Cap1","Cap2",0


@loop:
lea eax,lpText        ;Startadress of arry to eax
lea ebx,lpCap
invoke MessageBox,0,eax,ebx,MB_OK

;here compare if array 0 then jmp out


Greets


qWord

maybe this is what your looking for(?):

1. list of zero terminated strings. The end is marked by an second 0-byte
.data
    sz  db "string 1",0
        db "string 2",0
        db "string 3",0
        db "string 4",0
        db 0            ; mark end with empty string
.code
cld
mov edi,OFFSET sz
.while BYTE ptr [edi] != 0
    print edi,10,13         ; edi points to current string
    xor eax,eax
    mov ecx,-1
    repnz scasb
.endw

2. string array:
.data
    sz1 db "string 1",0
    sz2 db "string 2",0
    sz3 db "string 3",0
    sz4 db "string 4",0
   
    align 4
    szArray PCHAR OFFSET sz1
            PCHAR OFFSET sz2
            PCHAR OFFSET sz3
            PCHAR OFFSET sz4
            PCHAR 0             ; mark end of array
.code
; print string array
mov esi,OFFSET szArray
.while DWORD ptr [esi] != 0
    print [esi],10,13           ; esi is pointer to pointer to string
    lea esi,[esi+4]
.endw
FPU in a trice: SmplMath
It's that simple!

ragdog

Thanks for your help

This works only for a one array i need it for 2 arrays

ok i try it

donkey

Hi RagDog,

An array of strings is usually defined as follows:

SomeArrayLabel DB "String1",0,"String2",0,"String3",0, 0 ; Note extra NULL to terminate the array

In order to find a particular string you could use the scasb operation or some other mechanism to find NULL terminators. This little routine will return the offset in the array of any string, it will return -1 if the index is out of bounds. Note that the index is 0 based, the first string is at index 0, the second is at 1 etc...

GetArrayElement PROC uses edi ebx esi ArrayAddr:DWORD,cbArray:DWORD,Index:DWORD

xor ebx,ebx
mov esi, Index
test esi,esi
jnz @F
mov eax,ArrayAddr
ret
@@:
jns @F
mov eax,-1
ret
@@:

mov edi,ArrayAddr
mov ecx, cbArray
dec ecx
@@:
mov al,0
repne scasb
test ecx,ecx
jz @F
inc ebx
cmp ebx, esi
jne @B
mov eax,edi
ret

@@:
mov eax,-1
Ret
GetArrayElement ENDP


Call the function like this:

invoke GetArrayElement,offset SomeArrayLabel,SIZEOF SomeArrayLabel, 2

Edgar
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable

ragdog

Ok thanks

I complete routine for it :'(

I have think it is a small code for this solution

then can i make 2 or 3 calls then is smaller


I have this found here on board
Now change i this SendMessage with a Messagesbox
then have i only a problem with my captions strings


.data
omgarray db "One",0,"Two",0,0
.code
lea ecx,omgarray
PrintArray:
push ecx
invoke SendMessage,cbo, CB_ADDSTRING, 0,ecx
pop ecx
@@:
.if byte ptr [ecx] != 0
   inc ecx
   jmp @B
.else
   ;test to see if it is the end of the array
   .if byte ptr [ecx+1] != 0
      inc ecx       ;point next chain
      jmp PrintArray
   .endif
.endif



Thanks edgar