1

I created a structure that held basic information as well as some BYTE strings.. For instance:

 EXAMPLESTRUCT STRUCT
 somePrompt BYTE 20 DUP (0)
 ;other fields
 EXAMPLESTRUCT ENDS

My intent was to create an array of structures with messages relevant to that specific structure, initializing along the lines of:

ex1 EXAMPLESTRUCT <"Enter first">
ex2 EXAMPLESTRUCT <"Enter second">

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:

mov esi,OFFSET ex1
mov edx,OFFSET (EXAMPLESTRUCT PTR [esi]).somePrompt ;Error here

So, is my code wrong, or is this just an illegal use of OFFSET for some reason?

The only work around I've found was making the structure contain pointers and then initializing them to point at message already made:

WORKAROUND STRUCT
somePTR DWORD ?
;...
WORKAROUND ENDS

.data
msg BYTE "Hello World",0
struct1 WORKAROUND <OFFSET msg>

and then displaying a message along the lines of

mov esi,OFFSET struct1
mod edx,(WORKAROUND PTR [esi]).somePTR

Any other solutions/workarounds or should I just stick with pointers?

Charles
  • 50,943
  • 13
  • 104
  • 142
user994121
  • 77
  • 6

1 Answers1

1

You want to use the lea instruction.

lea edx,(EXAMPLESTRUCT PTR [esi]).somePrompt

See What's the purpose of the LEA instruction? for a little more about lea.

OFFSET is a compile-time construct. When you use the OFFSET directive, the assembler must be able to resolve it to a value at compile time. That's why you were getting an error--because the assembler can't know what the value of esi will be.

Community
  • 1
  • 1
Jim Mischel
  • 131,090
  • 20
  • 188
  • 351