3 ms·
I agree that this clever and useful, but I get the feeling that it could have been more so. I haven't done much assembly in a while, but I was heavily into it
by ggchappell 13y ago
I agree that this clever and useful, but I get the feeling that it could have been more so.
I haven't done much assembly in a while, but I was heavily into it once upon a time, and I recall that values with lots of 1s were useful. There is not quick way to generate those here. This means that we can write a single instruction to set any single bit using an inclusive OR and the proper immediate value, but we cannot write a single instruction to clear any single bit.
The reason I think a bit more cleverness might have helped is that there are so many values with multiple encodings. Anything where the 8-bit value ends with 0 has a different encoding as well. For example, a rotation of 0000 and an 8-bit value of 00000100 gives the same result as a rotation of 1111 and an 8-bit value of 00000001 (right?). Perhaps some of the redundant instructions could have been used to represent things ending in lots of 1s?
Regardless, an interesting and informative post. :-)
- tlb 13y agoYou can get trailing ones by subtracting 1: 0x01000000 - 1 = 0x00ffffff so you can generate any number of trailing ones with 2 instructions.
- eckzow 13y agoClearing an arbitrary bit actually is supported (as mentioned in the article: "you can set, clear, or toggle any bit with one instruction"). The specific details require you to dig a bit past explaining just the immediate encoding, but in the clearing case there's a dedicated instruction for clearing the bit specified by the immediate: BIC - Bit Clear (immediate) performs a bitwise AND of a register value and the complement of an immediate value, and writes the result to the destination register. As I mentioned in my other post, zero-rotation encodings are gamed out as well (to allow byte repetition).
- ggchappell 13y ago> BIC - Bit Clear (immediate) Ah, didn't catch that.