Skip to content

Instantly share code, notes, and snippets.

@BlueFalconHD
Created June 15, 2025 01:34
Show Gist options
  • Save BlueFalconHD/ac7c92852a2a5647e0f17cc7803574df to your computer and use it in GitHub Desktop.
Save BlueFalconHD/ac7c92852a2a5647e0f17cc7803574df to your computer and use it in GitHub Desktop.
Turing complete 'SPACIAL INVASION' assembly solution
# UNIVERSAL OPERAND CONSTANTS
const or0 0b000000
const ir0 0b000000
const or1 0b000001
const ir1 0b001000
const or2 0b000010
const ir2 0b010000
const or3 0b000011
const ir3 0b011000
const or4 0b000100
const ir4 0b100000
const or5 0b000101
const ir5 0b101000
const OUT 0b000110
const IN 0b110000
const never 0b000000
const eq_0 0b000001
const lt_0 0b000010
const lte_0 0b000011
const always 0b000100
const neq_0 0b000101
const leq_0 0b000110
const lt_0 0b000111
# ROBOT CONTROLS
const rc_left 0
const rc_fwd 1
const rc_right 2
const rc_nop 3
const rc_use 4
const rc_shoot 5
# TILE IDs
const tl_nothing 0
const tl_crate 40
const tl_wall 1
const tl_rat 33
# ENTRY
LDIR0+tl_rat
MOV+ir0+or5 # copy id of rat to r5
### get in front of crates ###
LDIR0+rc_left
MOV+ir0+OUT # left
LDIR0+rc_fwd
MOV+ir0+OUT # forward
MOV+ir0+OUT # forward
LDIR0+rc_right
MOV+ir0+OUT # right
LDIR0+rc_fwd
MOV+ir0+OUT # forward
MOV+ir0+OUT # forward
##############################
### check target ###
label check_target
MOV+IN+or1
MOV+ir5+or2
SUB
LDIR0+sleep
CJR0+neq_0 # sleep if ID != tl_rat
LDIR0+shoot
CJR0+eq_0 # shoot if ID == tl_rat
####################
### sleep ###
label sleep
LDIR0+rc_nop # do nothing
MOV+ir0+OUT
LDIR0+0
MOV+ir0+or3
LDIR0+check_target
CJR0+eq_0
#############
### shoot ###
label shoot
laser
LDIR0+rc_shoot
MOV+ir0+OUT # shoot
LDIR0+0
MOV+ir0+or3
LDIR0+check_target
CJR0+eq_0
#############

The following are the decimal definition values of each instruction:

  • ADD: 68
  • AND: 67
  • CJR0: 192
  • LDIR0: 0
  • MOV: 128
  • NAND: 65
  • NOR: 66
  • OR: 64
  • SUB: 69

In my format, to make it easier, I encoded the operands for the mov instruction as constants. You have <o|i>r<0-5> along with IN and OUT. Registers prefixed with i are interpreted as the input register, or in the move instruction, the source. o is interpeted as the destination. Because of the format, it doesn't matter what order the operands are in, they just must have a plus to combine them (bitwise or):

# these are the same
MOV+ir0+or1
MOV+or1+ir0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment