flat assembler
Message board for the users of flat assembler.
Index
> Windows > How to handle bit fields in FASM structs? |
Author |
|
Trinitek 08 Jun 2016, 09:59
You can use the bit test instructions.
bts [example], 3 will set the fourth bit, for example. |
|||
08 Jun 2016, 09:59 |
|
Trinitek 08 Jun 2016, 10:15
I dug through a project and found my implementation for creating enums and bitfields.
The macros... Code: macro enum eName*, [members*] { common local i i = 0 forward eName#.#members = i i = i + 1 } macro bitfield bName*, [members*] { common enum bName#.bit, members local i i = 1 forward bName#.#members = i i = i * 2 } Code: bitfield r,\ HMIN,\ HMAX,\ VMIN,\ VMAX,\ VPADDLELEFT,\ VPADDLERIGHT,\ HPADDLE Code: ; The macros allow you to perform bitwise operations using the traditional OR, AND, TEST, etc. instructions, like so... test ax, r.HMIN or r.HMAX jz .horizontalPaddle ; are at least one of the horizontal bits set? ; And the n-th bit offset is accessible for use with the 386 bit test instructions, like so... bt ax, r.bit.HPADDLE ; is the horizontal paddle collision bit set? jnc .verticalPaddle |
|||
08 Jun 2016, 10:15 |
|
fatygant 08 Jun 2016, 13:12
Hi Trinitek,
So, if I get it right (FASM macros are still the topic I have not handled yet...), first I should define the bitfield: bitfield dcbFLAGS, fBinary,fParity,fOutxCtsFlow,fOutxDsrFlow,fDtrControl,fDsrSensitivity,fTXContinueOnXoff,fOutX,fInX,fErrorChar,fNull,fRtsControl,fAbortOnError,fDummy2 and then use it when defining DCB structure? Like this: Code: struct DCB DCBlength dd BaudRate dd flags dcbFLAGS wReserved dw ... ends And what about fDtrControl (and fRtsControl) which takes 2 bits? Should I create two enums like fDtrControl1 and fDtrControl2? Thank you for your input - it helped a lot. |
|||
08 Jun 2016, 13:12 |
|
Trinitek 08 Jun 2016, 16:28
Your bitfield definition is good, but in your struct, you would still define 'flags' as a dd type. You need to try to remember that the symbols created by my bitfield macro are just a collection of assembly-time equates that are assigned to numbers. It does not create a new type. Here's another example using your struct...
Code: ; Let's set the fParity flag bts [DCB.flags], dcbFLAGS.bit.fParity Last edited by Trinitek on 08 Jun 2016, 16:59; edited 1 time in total |
|||
08 Jun 2016, 16:28 |
|
fatygant 08 Jun 2016, 16:57
Trinitek,
somethink like this works perfectly well: Code: macro enum name*,[stuff] { common local x x=0 struc name \{. dd ?\} forward x=x+1 stuff=x } and then Code: enum FLOWCONTROL,NoFlowControl,CtsRtsFlowControl,CtsDtrFlowControl,DsrRtsFlowControl,DsrDtrFlowControl,XonXoffFlowControl struct CONFIG mask dd ?,? pszPortName dq ? cchTextMax dd ? dwBaudRate dd ? bParity db ? bDataBits db ? bStopBits db ? fDiscardNull db ? flowControl FLOWCONTROL ends but indeed - my enum macro is different than yours. And what do you mean when saying: there are no structs in FASM?? |
|||
08 Jun 2016, 16:57 |
|
Trinitek 08 Jun 2016, 17:06
Completely forgot that structs are provided by struct.inc. I don't use it often. I went to correct myself but you beat me to it.
|
|||
08 Jun 2016, 17:06 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.