title: Assembly Language x86: Offset of an indirect operand to a structure
body: <p>I created a structure that held basic information as well as some BYTE strings.. For instance:</p>
  
  <pre><code> EXAMPLESTRUCT STRUCT
   somePrompt BYTE 20 DUP (0)
   ;other fields
   EXAMPLESTRUCT ENDS
  </code></pre>
  
  <p>My intent was to create an array of structures with messages relevant to that specific structure, initializing along the lines of:</p>
  
  <pre><code>ex1 EXAMPLESTRUCT &lt;"Enter first"&gt;
  ex2 EXAMPLESTRUCT &lt;"Enter second"&gt;
  </code></pre>
  
  <p>Referencing the address of the structure field directly (mov edx, OFFSET ex1.somePrompt) worked fine, but when using indirect addressing I kept getting an OFFSET error:</p>
  
  <pre><code>mov esi,OFFSET ex1
  mov edx,OFFSET (EXAMPLESTRUCT PTR [esi]).somePrompt ;Error here
  </code></pre>
  
  <p>So, is my code wrong, or is this just an illegal use of OFFSET for some reason?</p>
  
  <p>The only work around I've found was making the structure contain pointers and then initializing them to point at message already made:</p>
  
  <pre><code>WORKAROUND STRUCT
  somePTR DWORD ?
  ;...
  WORKAROUND ENDS
  
  .data
  msg BYTE "Hello World",0
  struct1 WORKAROUND &lt;OFFSET msg&gt;
  </code></pre>
  
  <p>and then displaying a message along the lines of</p>
  
  <pre><code>mov esi,OFFSET struct1
  mod edx,(WORKAROUND PTR [esi]).somePTR
  </code></pre>
  
  <p>Any other solutions/workarounds or should I just stick with pointers?</p>