News:

Download Pelles C here: http://www.smorgasbordet.com/pellesc/

Main Menu

MACROS

Started by HellOfMice, December 30, 2024, 12:40:48 PM

Previous topic - Next topic

Vortex

Hi Philippe,

This version aligns the structure to QWORD boundary :

sample STRUCT

    x           db ?
    y           db ?
    padding     db 6 dup(?)

sample ENDS
Code it... That's all...

HellOfMice

#16
Hello My Master Vortex.
sample STRUCT 8
x            db ?
Y            db ?
sample ENDS

This one too

Ok I know how to align a structure but if somewhere two members of this structure must be aligned on a 16 byte boundary and the orhers on 4 bytes? Except with padding I don't see how to do

HellOfMice

Pelle's also aligns very well the code on 16 bytes and data on 4 bytes

Vortex

Hi Philippe,

QuoteOk I know how to align a structure but if somewhere two members of this structure must be aligned on a 16 byte boundary and the orhers on 4 bytes? Except with padding I don't see how to do

You are right. Consider this simple example :

sample STRUCT 16

    x           dd ?
    y           dd ?
    z           oword ?

sample ENDS


y and z are aligned to 16 byte boundary.

OWORD = 16 bytes
Code it... That's all...

HellOfMice

#19
Hello Vortex,

Or directly like this

sample STRUCT 16
    x           OWORD ?
    y           OWORD ?
    z           OWORD ?
sample ENDS

In this case the structure address will have to be aligned on a multiple of 16
As we don't touch to the prolog I declare a Tmp variable

LOCAL TMP[256]:Byte

LEA RAX,TMP
AND RAX,NOT 15
MOV PtrStructure,RAX

What Do you think?

If the stack is aligned by 4 bytes, declare a dummy variable
LOCAL Dummy[16]:BYTE
LOCAL MyStruct:STRUCTURE

One thing I don't understand is if I had six strings I must repeat it for each string.

Philippe

Vortex

Hi Philippe,

Try to declare all your structuresas as LOCALs. We can introduce dummy local variables between those critical LOCALs to satisfy the alignmnet requirements.
Code it... That's all...

HellOfMice

Hi Vortex,


That's what I did but if we could have a directive like ALIGN that would be great.


Yestirday I looked at a disassembler written in C.
There were many structures using many UNIONS and records, very hard to read and to translate


EVEN POH2iNC DID NOT ARRIVED TO TRANSLATE
I have a keyboard that itself when it muts write in uppercase.


Have a look:



#ifdef _ENABLE_VEX_INFO
struct vex_info {
    struct {
        uint8_t type;
        union {
            struct byte2 {
                uint8_t vex_pp: 2;
                uint8_t vex_l: 1;
                uint8_t vex_v: 4;
                uint8_t vex_r: 1;
            } vexc5b;
            uint8_t val5;
        };
        union {
            struct byte3 {
                uint8_t vex_m : 5;
                uint8_t vex_b : 1;
                uint8_t vex_x : 1;
                uint8_t vex_r : 1;


                uint8_t vex_pp : 2;
                uint8_t vex_l : 1;
                uint8_t vex_v : 4;
                uint8_t vex_w : 1;
            } vexc4b;
            uint16_t val4;
        };
    };
};
#endif


struct instruction {
    uint64_t disp;
    uint64_t imm;
    uint64_t label;


#ifdef _ENABLE_VEX_INFO
    struct vex_info _vex;
#endif


#ifdef _ENABLE_RAW_BYTES
    uint8_t instr[15];
#endif


    uint8_t prefixes[4];
    uint8_t op;


    union
    {
        struct
        {
            uint8_t rm  : 3;
            uint8_t reg : 3;
            uint8_t mod : 2;
        } bits;
        uint8_t value;
    } modrm;


    union
    {
        struct
        {
            uint8_t rex_b : 1;
            uint8_t rex_x : 1;
            uint8_t rex_r : 1;
            uint8_t rex_w : 1;
        } bits;
        uint8_t value;
    } rex;


    union
    {
        struct
        {
            uint8_t  base   : 3;
            uint8_t  index  : 3;
            uint8_t  scaled : 2;
        } bits;
        uint8_t value;
    } sib;


    uint8_t vex[3];


    int length;
    int disp_len;
    int imm_len;


    uint16_t set_prefix; // bit mask
    uint16_t set_field;
    uint8_t  jcc_type;


    int8_t vex_cnt;
    int8_t prefix_cnt;
};



:-\ :-* :'(

Vortex

Another converter :

3. About h2incX
This tool's purpose is to convert C header files to Masm-style include files.
It is much more powerful than Microsoft's h2inc tool. The main purpose is to convert the Win32 include files,
but it should work with any C header files as well. It is a simple Win32 console application, but a 32bit DOS extended binary version is included as well to be used on Non-Win32 platforms.


https://www.terraspace.co.uk/uasm.html#p3
Code it... That's all...

Vortex

Code it... That's all...

HellOfMice

Thank You Vortex.
One thing is strange with PoAsm is using union, or I don't understand. I never use them.
h2IncX is more complete that PoH2Inc.
I would use it it with the "-D3" parameter.


Gave a good day Philippe

HellOfMice

I tried tocompile JWAsm but too many errors in the source file

TimoVJL

#26
May the source be with you

HellOfMice


Vortex

Hi Timo,

Many thanks.
Code it... That's all...