Sunday 29 June 2008

Infinite Loop

More often than not, infinite loops are created by programming errors and are quickly dealt with. In sympathy for this highly persecuted group of programs, a safe haven has been created on retro code. The two infinite loops below are highly optimized examples. In fact, the actual loops are only 1 byte long!

Z80 Infinite Loop
  ld hl, HERE
HERE:jp (hl)
8080 Infinite Loop
  lxi h, HERE
HERE:pchl
Corewar Infinite Loop
  jmp #0, <-5 
In Corewar, the infinite loop finds its niche destroying small mobile programs called imps!

If you know any infinite loops in need of shelter, please post them in the comments below.

17 comments:

  1. label: goto label;

    ReplyDelete
  2. The 8080 & Z80 infinite loops are one instruction long but not one byte long. The 8080 JMP instruction is three bytes long. The Z80 added relative jumps which decreased local jumps to two bytes. I believe some processors (6502 maybe?) had a one-byte HLT instruction which was implemented as a jump to current location.

    ReplyDelete
  3. (let loop ()
    (loop))

    ReplyDelete
  4. @fgb: the Z80 code looks like 4 bytes, 3 bytes setup code and 1 byte for the actual loop.

    ReplyDelete
  5. EB FE <-- x86 machine code for "jmp $"

    ReplyDelete
  6. label: push word label
    retn

    ReplyDelete
  7. while True: pass

    ReplyDelete
  8. Brainf***:

    +[]

    Underload:

    (:^):^

    ReplyDelete
  9. M68K assembly, 1 instruction, 2 bytes:

    bra.b *

    ReplyDelete
  10. MIPS:
    label: add $0, $0, $0 #add can be anything
    j label

    ReplyDelete

Note: only a member of this blog may post a comment.