The MASM Forum

Specialised Projects => Compiler Based Assembler => Topic started by: Emil_halim on April 08, 2018, 12:06:57 AM

Title: bitfield in masm
Post by: Emil_halim on April 08, 2018, 12:06:57 AM
Hi all

what is the masm code that similar to this c struct
   
struct LDT_ENTRY {
  WORD    LimitLow;
  WORD    BaseLow;
  union {
    struct {
      BYTE    BaseMid;
      BYTE    Flags1;     // Declare as bytes to avoid alignment
      BYTE    Flags2;     // Problems.
      BYTE    BaseHi;
    } Bytes;
    struct {
      DWORD   BaseMid : 8;
      DWORD   _Type : 5;
      DWORD   Dpl : 2;
      DWORD   Pres : 1;
      DWORD   LimitHi : 4;
      DWORD   Sys : 1;
      DWORD   Reserved_0 : 1;
      DWORD   Default_Big : 1;
      DWORD   Granularity : 1;
      DWORD   BaseHi : 8;
    } Bits;
  } HighWord;
};

Title: Re: bitfield in masm
Post by: nidud on April 08, 2018, 01:45:09 AM
This is how the LDT_ENTRY structure is defined in winnt.inc (https://github.com/nidud/asmc/blob/master/include/winnt.inc#L2937).

Code: [Select]
LDT_ENTRY_R0 RECORD \
    ldt_BaseHi: 8,
    ldt_Granularity: 1,
    ldt_ldt_Default_Big:1,
    ldt_Reserved_0: 1,
    ldt_Sys: 1,
    ldt_LimitHi: 4,
    ldt_Pres: 1,
    ldt_Dpl: 2,
    ldt_Type: 5,
    ldt_BaseMid: 8

LDT_ENTRY STRUC
LimitLow dw ?
BaseLow dw ?
UNION ;HighWord
  STRUC ;Bytes
    BaseMid db ?
    Flags1 db ? ; Declare as bytes to avoid alignment
    Flags2 db ? ; Problems.
    BaseHi db ?
  ENDS
  STRUC ;Bits
    r0 LDT_ENTRY_R0 <>
  ENDS
ENDS
LDT_ENTRY ENDS
PLDT_ENTRY typedef ptr LDT_ENTRY
Title: Re: bitfield in masm
Post by: Emil_halim on April 08, 2018, 03:11:05 AM

thanks nidud;