cancel
Showing results for 
Search instead for 
Did you mean: 

Knowledge Base Articles

Accessing a Structure in Assembly

Anonymous
Not applicable

Accessing a Structure in Assembly

Question: How do I access a structure defined in C from an assembly (.asm) file?

 

Answer:

A structure and its elements declared in C may be accessed in assembly by adding an underscore to the name of the structure and by using offsets.  For example, if there is a structure:

struct sMyStruct
{
   BYTE bVariable1;
   BYTE bVariable2;
}sMyStruct;

This structure may be accessed in assembly like:

add [_sMyStruct + 0],1 // Access bVariable1
add [_sMyStruct + 1],1 // Access bVariable2

Equates may be created for the elements and may be used instead of absolute offsets.  For example:

VARIABLE1:   EQU   0
VARIABLE2:   EQU   1

mov A,[_sMyStruct + VARIABLE1]
mov A,[_sMyStruct + VARIABLE2]

0 Likes
Version history
Revision #:
1 of 1
Last update:
‎Mar 18, 2011 08:54 AM
Updated by:
Anonymous
 
Contributors