Hacker News new | past | comments | ask | show | jobs | submit login
What's your favorite weird CPU instruction? any architecture, any time period (twitter.com/noradotcodes)
22 points by mooreds on Nov 21, 2021 | hide | past | favorite | 13 comments



Motorola 8-bit 6809 (used in Radio Shack's mid 80s CoCo - Color Computer)

HFC - Halt and Catch Fire

edit: thought it was branch and....corrected

https://x86.fr/investigating-the-halt-and-catch-fire-instruc...


I think you meant HCF.


XLAT - Table Translate

I once used this to speed up text search by a few orders of magnitude in the days of MS-DOS. My search went from 30 seconds to scan 3 Megabytes to faster than disks could read it. (<3 seconds)


The IBM 1401 had instructions for reading a punch card, printing a line on the printer, and punching a card. It also had an instruction (Write, Read, and Punch) that did all 3 at once (this machine had no channels/DMA, so this was how you got overlap). I'm told that watching a program run was funny: the machine would sit silent, then all 3 peripherals would spring into action, and then there would be silence.

The past is truly a different world.


Picking up on the "three at once" theme, the 1-bit computer I built in the 1980's has an instruction that does three things.

The computer only has one instruction, so I didn't bother to give the instruction a name. But it performs an input, an output and a 2-way branch. I hope this is weird enough to deserve mention in this thread. :)

The project was mentioned at least twice previously on HN:

https://news.ycombinator.com/item?id=12469790

https://news.ycombinator.com/item?id=7616831


PPC: eieio (enforce in-order execution of io)


PowerPC also had instructions like "rlwimi." with five operands plus implicitly cr0. It's rather startlingly complex for a "RISC" architecture.


Not an instruction, but a register. The R register on the z80 was a useful source of (somewhat)random numbers.


Do nonexistent CPUs count? Redcode, used in the CoreWars programming game, has a SPL instruction which boils down to "branch both ways". You end up with two execution pointers taking turns. One keeps going as if the SPL is a nop. The other keeps going as if the SPL is an unconditional jump. Of course you're not limited to calling this just the once.


68000 - ABCD. Really it’s just the mnemonic that’s nice. It adds BCD numbers.


username related - read lots of stuff while doing nothing useful with it :)

other fun x86 ones:

CALL SP

will call whatever code has been pushed on the stack. Unlike PUSH SP, it works the same on 8086 and newer CPUs

RET -2 (16 bit; -4 or -8 for 32/64 bit)

return but leave address on stack

LAR

load access rights; doesn't trap to kernel, so you can use this in ring3 code to scan through segment selectors and find out which are accessible and what type they are. On any x64 Linux, you can switch between 32 and 64 bit modes via far call, and syscalls will work in both modes (though they use different numbers).


PDP-11, a single 1-word (16-bit) instruction that, if run from the top of the RAM, overwrites all of it with copied of itself:

MOV -(PC),-(PC)


bmm - make your own instruction

block register transfer - a contiguous block of registers to/from a contiguous block of memory

explicit cache manipulation (invalidate, validate w/o read, prefetch)

start a thread (Tera MTA)

full/empty bits on the MTA (read full blocks on empty memory until its filled)




Consider applying for YC's W25 batch! Applications are open till Nov 12.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: