using a data structure from my c header in an assembly file

Assembly does not have conventions like struct, in order to use structs from C you must first know how your C program is laying structs out in memory which may vary wildly between implementations and even compilations due to struct reordering. You will have to manually construct and read your structs in Assembly.

If you simply want to use the structure you laid out in your example however, you are in luck because the C standard dictates that the first item of a struct is always the first in memory and since you only have two items in that struct you can determine where the next item is with certainty.

Assume we are working on x86 and that edi is a pointer to your s_list

mov eax, DWORD [edi] ; eax now holds the data pointer
mov ebx, DWORD [edi + 4] ; 4 bytes is the size of a dword, which in turn is the size of all pointer types in x86, so if we look 4 bytes beyond the pointer to the `s_list` we will find the value for the pointer to next

If you want another way of thinking about this, try to look at the code you’ve written in C and write it without using struct anywhere, this will give you an idea of how it works in Assembly.

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top