title: Struct dereference in masm
body: <p>I'm experimenting with using masm32 to code in x86 assembly. I'm interfacing with some WinAPI calls, and I need to access structs via pointers.</p>
  
  <p>Here is my basic code:</p>
  
  <pre><code>.586
  .MODEL FLAT, C
  OPTION CASEMAP:NONE
  .STACK
  
  obj STRUCT
    field      DWORD       ?
  obj ENDS
  
  objPtr TYPEDEF PTR obj
  
  .CODE
  
  main PROC
    LOCAL inst : objPtr
  
  ; Assume inst is assigned to something (result of function call eg)
  
  
  main ENDP
  
  END main
  </code></pre>
  
  <p>So I've got a pointer to a struct, the pointer is given to me as the result of a function, so assume it points to a valid struct. What I want to know is how I can reassign some of its fields. In C, I'd use the -> operator to do so, for example:</p>
  
  <pre><code>inst-&gt;field = 42
  </code></pre>
  
  <p>I need to do the equivalent in my Assembly code. Is it possible without having to make a local copy of the struct to access directly? Do I perhaps need to put the pointer into a register? I've attempted some research by myself but I'm having difficulty understanding the code I see, or finding specific MASM examples.</p>
  
  <p>Help is much appreciated!</p>