There is a task:
Replace the combination 1011 in the given word with the combination 1101.

It is clear that there will be a cycle.

How can I apply to the lower 4 bits of an 8-bit register (for example, Al)?
How do I then replace the values?

    2 answers 2

    1. To access the low-order bits, you need to perform the and operation with the mask 1111 in a binary representation.
    2. Replacement of values ​​can be performed by xor operation with mask 0110 (since we know that there are 1011 numbers in this place).
    • It turns out, you need to first copy the values ​​so as not to spoil them with logical operations? - iluxa1810
    • If it is not possible to perform a bitwise operation without spoiling the original value, then yes. The exact answer, of course, depends on the assembler. - Doge

    If aligned to 4 bits, then you can do 4 checks without cycles, if at any offset, then save the original, set the mask to 110 (bin), do a cycle to 12 (dec), check for and $ 0f (hex) to equality 1011 (bin), if the xorim is equal to the mask with the original, then we shift using shr, for example, and the mask with shl and looping.