News:

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

string array

Started by slovach, October 28, 2007, 07:51:02 AM

Previous topic - Next topic

slovach

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]);
}

ToutEnMasm

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

slovach


zooba

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

drizz

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
The truth cannot be learned ... it can only be recognized.