views:

118

answers:

2

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.
+3  A: 

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.

Erwin Smout
Can you clarify more please?
Nick
He's proposing a lookup table with a result value for each of the 256 possible input values. The list is created using the DB command. Lookup is performed using a simple `move AL, start + index` instruction.
mafutrct
+5  A: 

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.

Paul R
Thank you Mr.Paul. This should be the code:OR AL, 10011001XOR AL, 10100011
Nick
@Nick: yes, that looks about right, depending on exactly what CPU and assembler you're using.
Paul R