Author Topic: bitfield in masm  (Read 488 times)

Emil_halim

  • Member
  • **
  • Posts: 111
bitfield in masm
« 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;
};


nidud

  • Member
  • *****
  • Posts: 1614
    • https://github.com/nidud/asmc
Re: bitfield in masm
« Reply #1 on: April 08, 2018, 01:45:09 AM »
This is how the LDT_ENTRY structure is defined in winnt.inc.

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

Emil_halim

  • Member
  • **
  • Posts: 111
Re: bitfield in masm
« Reply #2 on: April 08, 2018, 03:11:05 AM »

thanks nidud;