Accessing a Structure in Assembly
Anonymous
Not applicable
Mar 18, 2011
08:54 AM
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
Mar 18, 2011
08:54 AM
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]
Labels
- Tags:
- psoca 1
Rate this article:
Contributors
-
This widget could not be displayed.Anonymous