char packetData[256]; 
 unsigned long *ptr;
  memset( packetData, 0, 256 );
   strcpy( packetData, "blah" ); 
   ptr = (unsigned long *) &packetData[4];
    *ptr = htonl( 0x00000100 ); 
How would I convert this into a asm friendly syntax. it should produce a string like so blah(result of htonl) thanks for the help
Posted on 2001-02-11 23:14:00 by newbie
Thing to remember with ASM is that there are no types! Types are a construct for us the programmer, to help us think of about what is going on! :D The same is true of all languages, except they "enforce" types to make sure we (the programmers) don't do anything stupid. In C it is possible to cast data from one type to another, this simply makes the type checker treat the data differently, even though the data is the same. A character is a single byte, and so "text" is a series of bytes so:

char packetData[256];
Is the same as:

packetData     db            256     dup(?)
;name          size of unit  length  initialised value
;                                    dup(0) will initialise to 0s
Next is the pointer, in C a pointer is given a type, but as I said above types are meaningless in ASM! A pointer essentially contains the value of the address where the data is located. There is no special type, all you need to remember is that addresses are 32bit, and so you need to allocate 32 bits of space to hold this value (a DWORD) so:

unsigned long *ptr;
Is the same as:

ptr        DWORD       ?
;label     unit size   initial value (dont care)
As for the rest of the code, the memset isn't needed (if you declare packetData db dup(0)), Hutch has kindly provided a concatenation function in the MASM32.LIB, but you cannot pass literal text in ASM, so this must be declared too (sometext db "blah",0) invoke strcpy, ADDR packetData, ADDR sometext Not sure about the function's name (@ work, no docs, blah blah)! ptr = (unsigned long *) &packetData[4]; mov eax, ADDR packetData add eax, 4 There are better ways to do this, but I think this is quite easy to understand (plus no docs, so I can't test, and I know this works (I too am very new to ASM, and I don't want to mislead)). I don't know what htonl does (can't remember), but the code will be something like this:

invoke , whatever....
;Result in eax (probably, if not may be more complex!)

mov edx, ADDR packetData
add edx, 4
;As above, a better method would use lea, but I'll leave you to
;read up on it!

mov , eax
;Copy the contents of eax, to the address in memory that edx
;"points to"
I hope this helps, if it doesn't sorry! (But it is Monday, I am stupid, what do you expect? ;) ) Mirno
Posted on 2001-02-12 07:14:00 by Mirno