Hello! I have a function FUNC1 that takes a pointer to a structure, and I have been accessing it like this:

  val1 DWORD ?
  val2 WORD ?
  val3 BYTE ?



  mov ebx, arg  
  ;I use this method to access/change the elements
  mov , 678 ;just some example numbers
  mov , 70000

Is this an efficient way of doing it, or is there a better way? Thanx in advance. :-) Oh, by the way, if you have seen the topic I made called "Calling MASM Functions from within C", I did figure it out! :cool: This message was edited by Zir0, on 7/5/2001 12:51:15 PM This message was edited by Zir0, on 7/5/2001 12:54:28 PM
Posted on 2001-07-05 12:44:00 by Zir0
Thats as efficient as you'll get! The other way of doing it is like this:
 mov eax, (TSTR PTR ).val1 
Both will compile to the exact same code, but this way doesn't need a typedef. It can sometimes be a pain if you typedef too much stuff (every time I program C I get a million errors and I keep having to cast things as other data types :mad: ). Which way you do it is entirely up to you. Go with which ever suits your personal coding style best! In terms of efficiency, the only way one is better than the other is the ammount of typing needed :D Mirno
Posted on 2001-07-05 12:51:00 by Mirno
Thank you, Mirno.
Posted on 2001-07-05 12:53:00 by Zir0
Hi there! There is yet another approach (not very different from the previous ones tho') using ASSUME: ASSUME ESI: PTR BITMAPFILEHEADER MOV EDX,.bfOffBits That's it :) Latigo
Posted on 2001-07-05 14:01:00 by latigo
Ok, this is probably a stupid question, but am I right in assuming that both methods complie to the same thing? Forgive my ignorance, may it be temporary.
Posted on 2001-07-05 14:17:00 by Zadkiel
Besides the use of different registers, yes they assemble to the same code. Thomas
Posted on 2001-07-05 18:18:00 by Thomas
I never cared for ASSUME because until you ASSUME NOTHING the compiler goes along happily making assumptions you may not have intended. I'm not big on "action at a distance" in my code.

mov eax, (TSTR PTR ).val1  
is quite valid, and far better to use. I used to write my code this way until I hit upon this form:

mov eax, .TSTR.val1
Of course, it compiles to the same thing, but its the readability I'm concerned with here, and you type less this way. Also, if you have a structure

MyStruct  SomeStruct <>
You need not be so formal in declaring a pointer to it, as MASM32 has very minimal (if any) type checking. You can send it to a proc like so:

invoke Foo, ADDR MyStruct
Posted on 2001-07-05 19:26:00 by Ernie