Search code examples
assemblyx86bios

Which assembler dialect is the following syntax?


and dword ptr [edi], not (1 shl 2)

Would you mind pointing to literature that describes this dialect and/or provide equal syntax in other dialects? An explanation of the line would be helpful as well for my own edification.

FWIW, I am trying to port instructions in this dialect to coreboot which I believe uses, I guess, a GNU dialect. When I attempt to assemble with this instruction unchanged I get the following error from i386-elf-gcc:

./src/drivers/intel/fsp/cache_as_ram.inc: Assembler messages:
./src/drivers/intel/fsp/cache_as_ram.inc:74: Error: junk `PTR [edi]' after expression
./src/drivers/intel/fsp/cache_as_ram.inc:74: Error: too many memory references for `and'

Solution

  • The Microsoft Macro Assembler (ml.exe) [also known as MASM or MASM32] understands this construct.

    Its equal to:

    and dword ptr [edi], 0fffffffbh
    

    How?

    1. 1 shl 2 is equal to 4 (you move 1 two positions to the left: 100 in base 2 or 4 in base 10)

    2. Thus we have not 4 (you invert all bits in 100 in base 2)

    3. which gives 11111111111111111111111111111011 in base 2 (we are on 32-bit)

    4. this is equal to 0fffffffbh (0x0fffffffb ; 4294967291 in decimal)