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

StackOverflow https://stackoverflow.com/questions/2715754

  •  01-10-2019
  •  | 
  •  

Question

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.
Was it helpful?

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.

OTHER TIPS

One DB instruction defining an array of 256 "result" values, and one move instruction to move an element of this array into al, using the current value in al as an index.

Wouldn't that work ?

It might even be argued that this is in fact even a single-instruction solution, since the DB is not really an instruction that executes at run-time, rather it is a compile-time declarative.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top