how to write this statement in assembly?

const char * types[] = { "image/gif", "image/x-xbitmap", "image/jpeg", "image/pjpeg", "application/vnd.ms-excel", "application/msword", "application/vnd.ms-powerpoint", "*/*", NULL };
Posted on 2002-03-11 15:18:19 by dJed_mRaz
dJed_mRaz,

If I'm not wrong (I'm a bit rusty w/ c++), you need to define a string for each entry in the data section:

GIF db "image/gif", 0
BITMAP db "image/x-xbitmap", 0
JPEG db "image/jpeg", 0
PJPEG db "image/pjpeg", 0
EXCEL db "application/vnd.ms-excel", 0
WORD db "application/msword", 0
POWERPOINT db "application/vnd.ms-powerpoint", 0
ANY db "*/*", 0

Then you create an array of pointers (dwords) to hold the addresses of the strings (also in the data section), like this:

types dd 9 dup (0)

Finally, in the code section, you can fill the array with the addresses of the strings:

m2m types[0], OFFSET GIF
.
.
.
m2m types[7], OFFSET ANY

The last value types[8] should be 0 or NULL because of the definition.

I'm assuming that you won't be modifying the strings, otherwise things can get pretty messy.
Posted on 2002-03-11 15:35:07 by Lysic
m2m types[0], OFFSET GIF 


Don't use the m2m macro for this, OFFSET GIF is just a constant value (some mem location). You can move this value directly to types[0] with mov types[0], offset GIF.

Much easier is:


typesArr dd OFFSET GIF, OFFSET BITMAP
dd OFFSET JPEG, dd OFFSET PJPEG and so on


Thomas
Posted on 2002-03-11 15:45:54 by Thomas
cTEXT MACRO y

LOCAL sym
CONST segment dword public 'DATA'
IFIDNI <y>,<"">
sym db 0
ELSE
sym db y,0
ENDIF
CONST ends
EXITM <OFFSET sym>
ENDM


types dd cTEXT(<image/gif>), cTEXT(<image/x-xbitmap>), cTEXT(<image/jpeg>), cTEXT(<image/pjpeg>), cTEXT(<application/vnd.ms-excel>), cTEXT(<application/msword>), cTEXT(<application/vnd.ms-powerpoint>), cTEXT(<*/*>), NULL
That is all.
Posted on 2002-03-11 15:49:58 by bitRAKE
Come to think of it, I might be wrong...

I think what I showed you is an array of string addresses, while you really need an array of strings... Not quite sure about that one... though it looks like the guys who posted after me really know their stuff... :)
Posted on 2002-03-11 15:51:02 by Lysic
Lysic, you are correct as well, but there is no need
to write the constants at run-time in this situation.
Posted on 2002-03-11 16:01:13 by bitRAKE
thanks guys on your help.
Posted on 2002-03-11 16:23:55 by dJed_mRaz