But the problem lies in the fact that you use the constant NF_SUBSECTOR both as 16 and 32 bit?

Because otherwise no problems arose.

If you define as

**-$8000** the value is the same both 16 or 32 bit: $FFFF8000 or $8000, sign extended

And if you use

and.w #~NF_SUBSECTOR,d0

or

and.l #~NF_SUBSECTOR,d0

or

and #~NF_SUBSECTOR,d0

result is one:

and.x #$7fff,d

0,

that is the requested operation (logically for .w upper bits are untouched).

So, even if assembler default to 32bit, result is correct.

What's wrong with this?