Microsoft KB Archive/30887

= Accessing MASM Structure Fields in a Multimodule Program =

Article ID: 30887

Article Last Modified on 11/17/2003

-

APPLIES TO


 * Microsoft Macro Assembler 5.0
 * Microsoft Macro Assembler 5.1 Standard Edition
 * Microsoft Macro Assembler 6.0 Standard Edition

-



This article was previously published under Q30887



SUMMARY
To use a structure, defined in one module with the STRUC (STRUCT in MASM 6.0) operator, in another module with the Macro Assembler, you must take into account the fact that the structure definition must be available to both modules at assemble time. The structure field operator (.) can then be used to access the structure's contents.



MORE INFORMATION
The following program demonstrates the use of a structure in a two-module program: ; Source file 1:

EXTRN changecow:NEAR               ; Near function call

animals   STRUC                    ; Structure definition cat   db    &quot;catfield      &quot; dog   db    &quot;dogfield      &quot;   ; Field widths of 15 characters cow   db    &quot;cowfield      &quot; animals   ENDS

.MODEL small

.DATA PUBLIC zoo zoo       animals   <&quot;felix&quot;,&quot;spot&quot;,&quot;Holstein&quot;>  ; Initialize fields

.CODE main:     mov ax, @data            ; Make data addressable mov ds,ax mov es,ax               ; For string moves

call changecow          ; Change &quot;Holstein&quot; to &quot;Daisy&quot; retf END main


 * Source file 2:
 * In source file 2, structure definition must be available for the
 * field offsets. (Normally it would be placed in an include file,
 * then the INCLUDE operator would be used; however, for sake of
 * clarity, the structure definition has been placed in both files).
 * The structure information must be included here to correctly
 * associate the fields with the offset. The structure name does not
 * need to be &quot;animals&quot;; however, the structure fields should
 * correspond.

animals   STRUC                    ; Structure definition cat   db    &quot;catfield      &quot; dog   db    &quot;dogfield      &quot;   ; Field widths of 15 characters cow   db    &quot;cowfield      &quot; animals   ENDS

.MODEL small

.DATA EXTRN zoo:NEAR                      ; Let assembler know about zoo newcow   db     &quot;Daisy         &quot;    ; Replace cow with new name lenname  EQU    $ - newcow          ; Length of new name

.CODE PUBLIC changecow          ; Changes cow field to &quot;Daisy&quot; changecow PROC mov    di, offset zoo.cow ; es:di should now point to destination mov    si, offset newcow  ; ds:si should now point to the source mov    cx, lenname        ; Length of new string rep    movsb              ; Do replacement ret changecow ENDP END

Additional query words: kbinf 5.00 5.10 6.00

Keywords: KB30887

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.