Skip to content

Instantly share code, notes, and snippets.

@durka
Created May 29, 2009 06:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save durka/119813 to your computer and use it in GitHub Desktop.
Save durka/119813 to your computer and use it in GitHub Desktop.
;; First example:
Clojure=> (subleq 3 4 [5 8 12 0 0 42 0 0 144 1 2 3 4 5 6 7] {:ip 0}) ; here x = 42 and y = 144
[[5 8 12 0 0 42 0 0 102 1 2 3 4 5 6 7] {:out false, :in false, :ip 3}]
; Mem[A] has been subtracted from Mem[B], but Mem[B] is 102 so we do not jump to C
Clojure=> (subleq 3 4 [5 8 12 0 0 144 0 0 42 1 2 3 4 5 6 7] {:ip 0}) ; now switch Mem[A] and Mem[B]
[[5 8 12 0 0 144 0 0 -102 1 2 3 4 5 6 7] {:out false, :in false, :ip 12}]
;; Second example, with a negative operand:
Clojure=> (subleq 3 4 [5 8 -12 0 0 42 0 0 144 1 2 3 14 5 6 7] {:ip 0})
[[5 8 -12 0 0 42 0 0 102 1 2 3 14 5 6 7] {:out false, :in false, :ip 3}]
Clojure=> (subleq 3 4 [5 8 -12 0 0 144 0 0 42 1 2 3 14 5 6 7] {:ip 0})
[[5 8 -12 0 0 144 0 0 -102 1 2 3 14 5 6 7] {:out false, :in false, :ip 14}]
; Note that the program jumps to address 14 (which happens to have a 6 in it), which comes from cell 12, named by C
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment