flat assembler
Message board for the users of flat assembler.

Index > Main > C struct

Author
Thread Post new topic Reply to topic
donn



Joined: 05 Mar 2010
Posts: 321
donn 11 Nov 2015, 16:33
Hi,

I have been editing Vid's msvc example, thought it may be useful to practice converting a C linked list to Asm as a C library. How should I reference Asm structs? I read that struct members are sequentially ordered in memory, but not sure how to access them or if I should be using the struc directive. If there are any other examples I could examine or documentation to read up on, will certainly take a look. I have been experimenting with many different variations but will keep trying.

Code:
extern struct Struct1{
        int member1;
};
    




Thanks a lot


Description:
Download
Filename: asm.asm
Filesize: 463 Bytes
Downloaded: 421 Time(s)

Description: cl /c c.c
Download
Filename: c.c
Filesize: 339 Bytes
Downloaded: 430 Time(s)

Post 11 Nov 2015, 16:33
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20343
Location: In your JS exploiting you and your system
revolution 11 Nov 2015, 23:32
You define the internal structure layout separately from the external reference. Once you have the reference address (from the external label) then it is up to your code how it interprets the data that exists there (perhaps with a 'struc', 'struct' or just plain code).
Post 11 Nov 2015, 23:32
View user's profile Send private message Visit poster's website Reply with quote
donn



Joined: 05 Mar 2010
Posts: 321
donn 12 Nov 2015, 15:41
Awesome, got it, thanks!

c.h (Not able to upload attachment of this, "The Extension h is not allowed"):
Code:

struct Struct1{
        int member1;
} struct1;
    

Code:
extern struct Struct1 struct1;
    


Code:
public struct1 as '_struct1'
    


Code:
        struc Struct1 member1{
                .member1 dd member1
        }

        struct1 Struct1 77
    


Description:
Download
Filename: asm.asm
Filesize: 534 Bytes
Downloaded: 439 Time(s)

Description: cl c/ c.c
link c.obj asm.obj

Download
Filename: c.c
Filesize: 349 Bytes
Downloaded: 438 Time(s)

Post 12 Nov 2015, 15:41
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.