You are required to write a maximum of two instructions in assembly to do the following:
The AND operation can be used for clearing one or more bits. For example, say the BL register contains 0011 1010. If you need to clear the high-order bits to zero, you AND it with 0FH.
The least significant byte of AX can be used as a single 8-bit register called AL, while the most significant byte of AX can be used as a single 8-bit register called AH. These names refer to the same physical register.
The EAX, EBX, ECX, EDX, EBP, EDI, and ESI registers are all 32-bit general-purpose registers, used for temporary data storage and memory access. Some of CPU instructions modify specific registers.
al and ah are the 8-bit, "char" size registers. al is the low 8 bits, ah is the high 8 bits. They're pretty similar to the old 8-bit registers of the 8008 back in 1972.
The trick here is to do the following:
use an OR instruction to set bits 0, 3, 4 and 7
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With