Search code examples
visual-studio-2010assemblyx86inline-assembly

Access specific bit in embedded X86 assembly


I am trying to acces a specific bit and modify it. I have moved 0x01ABCDEF (hex value) into ecx and want to be able to check bit values at specific position. For example I must take byte 0 of 0x01ABCDEF (0xEF) check if bit at position 7 is 1 set the middle 4 bits to 1 and the rest to 0.


Solution

  • It's been years since I've done asm, but you want to and your value with 0x80 and if the result is zero your bit is not set so you jump out, otherwise continue along and set your eax to the value you want (I assume the four bits you mean are the 00111100 in the fourth byte.

    For example (treat this as pseudo code as it's been far too long):

          and eax, 0x80         
          jz  exit
          mov eax, 0x3C
    exit: