The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: slovach on October 28, 2007, 07:51:02 AM

Title: string array
Post by: slovach on October 28, 2007, 07:51:02 AM
in C i would do something like this as it's much cleaner and nicer than individually adding each one. but how would i go about accomplishing the same thing in mASM?

const char *omgarray[] = { "One", "Two" };
int count;
for(count = 0; Count < 2; Count++)
{
     SendMessage(cbo, CB_ADDSTRING, 0, omgarray[Count]);
}
Title: Re: string array
Post by: ToutEnMasm on October 28, 2007, 08:19:21 AM
Hello,
Quote
.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
Title: Re: string array
Post by: slovach on October 28, 2007, 08:59:20 AM
thank you!
Title: Re: string array
Post by: zooba on October 28, 2007, 11:06:24 AM
The C style one is actually an array of pointers to strings, more like this:

stringOne BYTE "One", 0
stringTwo BYTE "Two", 0
omgarray DWORD stringOne, stringTwo


There's plenty of examples on the forum for this sort of thing. A search for "string array" will probably find at least a couple of topics with the same subject.

Cheers,

Zooba :U
Title: Re: string array
Post by: drizz on October 28, 2007, 05:17:50 PM
Quote from: slovach on October 28, 2007, 07:51:02 AM
in C i would do something like this as it's much cleaner and nicer than individually adding each one.
it can be clean and nice in masm too if you use macros.omgarray PCHAR T("One"),T("Two")


T MACRO __qstr:VARARG
LOCAL __sym,__seg
__seg EQU <.code>
%IFIDNI <@CurSeg>,<_DATA>
__seg EQU <.data>
ENDIF
.const
ALIGN 4
__sym LABEL BYTE
IFDIFI <__qstr>,<>
DB __qstr
ENDIF
DB 0
__seg
EXITM <OFFSET __sym>
ENDM