NO

Author Topic: MACROS  (Read 1550 times)

Offline Vortex

  • Member
  • *
  • Posts: 975
    • http://www.vortex.masmcode.com
Re: MACROS
« Reply #15 on: January 19, 2025, 09:04:28 PM »
Hi Philippe,

This version aligns the structure to QWORD boundary :

Code: [Select]
sample STRUCT

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

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

Offline HellOfMice

  • Member
  • *
  • Posts: 362
  • Never be pleased, always improve
Re: MACROS
« Reply #16 on: January 19, 2025, 09:09:54 PM »
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
« Last Edit: January 19, 2025, 09:13:04 PM by HellOfMice »
--------------------------------
Kenavo

Offline HellOfMice

  • Member
  • *
  • Posts: 362
  • Never be pleased, always improve
Re: MACROS
« Reply #17 on: January 19, 2025, 09:14:17 PM »
Pelle's also aligns very well the code on 16 bytes and data on 4 bytes
--------------------------------
Kenavo

Offline Vortex

  • Member
  • *
  • Posts: 975
    • http://www.vortex.masmcode.com
Re: MACROS
« Reply #18 on: January 21, 2025, 08:46:52 PM »
Hi Philippe,

Quote
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

You are right. Consider this simple example :

Code: [Select]
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...

Offline HellOfMice

  • Member
  • *
  • Posts: 362
  • Never be pleased, always improve
Re: MACROS
« Reply #19 on: January 22, 2025, 01:10:43 AM »
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
« Last Edit: January 22, 2025, 01:14:26 AM by HellOfMice »
--------------------------------
Kenavo

Offline Vortex

  • Member
  • *
  • Posts: 975
    • http://www.vortex.masmcode.com
Re: MACROS
« Reply #20 on: January 23, 2025, 10:06:23 PM »
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...

Offline HellOfMice

  • Member
  • *
  • Posts: 362
  • Never be pleased, always improve
Re: MACROS
« Reply #21 on: January 24, 2025, 02:08:55 AM »
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:


Code: [Select]
#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;
};


 :-\ :-* :'(
--------------------------------
Kenavo

Offline Vortex

  • Member
  • *
  • Posts: 975
    • http://www.vortex.masmcode.com
Re: MACROS
« Reply #22 on: January 24, 2025, 09:26:55 AM »
Another converter :

Code: [Select]
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...

Offline Vortex

  • Member
  • *
  • Posts: 975
    • http://www.vortex.masmcode.com
Re: MACROS
« Reply #23 on: January 24, 2025, 01:16:44 PM »
Code it... That's all...

Offline HellOfMice

  • Member
  • *
  • Posts: 362
  • Never be pleased, always improve
Re: MACROS
« Reply #24 on: January 24, 2025, 01:23:31 PM »
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
--------------------------------
Kenavo

Offline HellOfMice

  • Member
  • *
  • Posts: 362
  • Never be pleased, always improve
Re: MACROS
« Reply #25 on: January 24, 2025, 02:02:06 PM »
I tried tocompile JWAsm but too many errors in the source file
--------------------------------
Kenavo

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2215
Re: MACROS
« Reply #26 on: January 24, 2025, 04:01:21 PM »
« Last Edit: January 24, 2025, 04:03:58 PM by TimoVJL »
May the source be with you

Offline HellOfMice

  • Member
  • *
  • Posts: 362
  • Never be pleased, always improve
Re: MACROS
« Reply #27 on: January 24, 2025, 04:55:53 PM »
ThankY ou :)
--------------------------------
Kenavo

Offline Vortex

  • Member
  • *
  • Posts: 975
    • http://www.vortex.masmcode.com
Re: MACROS
« Reply #28 on: January 24, 2025, 09:48:37 PM »
Hi Timo,

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