Ask HN: Favourite Assembly Instructions?

5 points by RetroTechie ↗ HN
One for the low-level gurus among you: what is/are your favourite assembly-language instructions, accross the ages & instruction sets?

To get this started: for the good 'ol Z80, I'm torn between Decrement-and-Jump-if-Not-Zero (DJNZ), and Decimal Adjust Accumulator (DAA). Rarely used ComPare, Increment & Repeat (CPIR) could be another contender.

On RISC-V, I much like the Set-Less-Than (SLT..) instructions. Great for replacing conditional branches with branchless, sequential math.

Your favourites?

4 comments

[ 1.7 ms ] story [ 16.1 ms ] thread
HCF - Halt and Catch Fire.
I always liked rlwimi on PowerPC. It rotates the source n bits, then writes any contiguous section of bits over the corresponding bits in the destination register. This allows copying any bitfield from any position in one register into another. Basically either of these:

  out = (out & ~mask) | (in << shift & mask)
  out = (out & ~mask) | (in >> shift & mask)
Z80's EXX to swap with the shadow registers was interesting (meant for fast interrupt response so you didn't have to save registers to memory).
pext/pdep are incredible, I'm hoping to see them in more SIMD ISAs in the future.

But my favorite is the 8x8 bit matrix transpose SIMD instruction (gf2p8affine, which does a bit more, buy I care about the tranapose). Combined with SIMD byte permutes it allows you to do things like: arbitrarily permute bits in SIMD elements, find the invers of a permutation, very fast histograming/binning

BR 14 (IBM assembler)

Because it has a utility named after it. Hence my name.