Search code examples
assemblyx86xormasm

Write a maximum of two instructions to clear, set and complement some bits in the AL register


You are required to write a maximum of two instructions in assembly to do the following:

  1. Clear bits 0 and 7 of register AL, i.e. make them 0
  2. Set bits 3 and 4 of register AL, i.e. make them 1.
  3. Complement bits 1 and 5 of register AL.
  4. Keep all other bits in the register AL as is without changing their values.

Solution

  • The trick here is to do the following:

    1. use an OR instruction to set bits 0, 3, 4 and 7

    2. use an XOR instruction to complement bits 0, 1, 5 and 7

    Note that bits 0 and 7 first get set in (1) and then cleared in (2).

    I'll leave the actual asm instructions to you, since this is your homework, after all.