Search code examples
assemblyemu8086

Toggle nibbles in a 16 bit register (8086)


I want to toggle (invert) the most significant nibble and the least significant nibble of AX register. What will be sequence of assembly language instructions for this?


Solution

  • I'd strongly suggest reading the manuals for these processors if you're going to be writing any assembly for them. This can be done in a single instruction:

    XOR AX, 0xF00F
    

    Inverting bits is easily done using an Exclusive or with 1 bits. By performing an exclusive or where the upper and lower nibbles of a 16-bit word are set, the bits in those nibbles of AX are inverted.