Shifty

From Esolang
Jump to navigation Jump to search

Shifty is an esoteric assembly language created by User:D. The primary operation is bit shifting.

Instructions

There are two unbounded registers, A and B.

  • SLB: Set lowest bit of A to 1.
  • LSH: Left shift A by 1 bit.
  • RSK x: Right shift A (storing parity). If parity == 0, skip forward x instructions.
  • SKZ x: If A == 0: Skip forward x instructions.
  • XCH Exchange A and B.
  • BR x: Unconditionally branch back x instructions.

Examples

Cyclic tag system simulator

; Cyclic tag simulator

    SLB
rules:

rule_1:
    RSK end_1

; Move everything from A to B;
; (reversing bit order)

copy_1:
    SKZ end_copy_1
    XCH
    LSH
    XCH

    RSK skip_bit_1
    XCH
    SLB
    XCH

skip_bit_1:
    BR copy_1

end_copy_1:
; Production 1: 011
; (store it in reverse bit order)
    SLB
    LSH
    SLB
    LSH

; Move everything from B to A (still reversing bit order)

    XCH

second_copy_1:
    SKZ end_second_copy_1
    XCH
    LSH
    XCH

    RSK second_skip_bit_1
    XCH
    SLB
    XCH

second_skip_bit_1:
    BR second_copy_1

end_second_copy_1:

end_1:

    ; Same logic for other productions

    ; ...

    ; Jump back to start
    BR rules