Skip to content

Instantly share code, notes, and snippets.

@nitrix
Created January 11, 2016 00:13
Show Gist options
  • Select an option

  • Save nitrix/2c6c5067b6d400fbe51b to your computer and use it in GitHub Desktop.

Select an option

Save nitrix/2c6c5067b6d400fbe51b to your computer and use it in GitHub Desktop.
nitrix@pluto ~/projects/ni/boot [develop]$ php vm.php test
Instruction SBNZ [$0=9, $1=0, $2=8, $3=-1]
Enter a character: f
Performing `$8 = $0 - $9`, the values are `-11 = 102 - 113`
Instruction SBNZ [$4=1, $5=1, $6=8, $7=0]
Performing `$8 = $1 - $1`, the values are `0 = 0 - 0`
Result is zero, branching to 0
Instruction SBNZ [$0=9, $1=0, $2=8, $3=-1]
Enter a character: g
Performing `$8 = $0 - $9`, the values are `-10 = 103 - 113`
Instruction SBNZ [$4=1, $5=1, $6=8, $7=0]
Performing `$8 = $1 - $1`, the values are `0 = 0 - 0`
Result is zero, branching to 0
Instruction SBNZ [$0=9, $1=0, $2=8, $3=-1]
Enter a character: h
Performing `$8 = $0 - $9`, the values are `-9 = 104 - 113`
Instruction SBNZ [$4=1, $5=1, $6=8, $7=0]
Performing `$8 = $1 - $1`, the values are `0 = 0 - 0`
Result is zero, branching to 0
Instruction SBNZ [$0=9, $1=0, $2=8, $3=-1]
Enter a character: q
Performing `$8 = $0 - $9`, the values are `0 = 113 - 113`
Result is zero, branching to -1
Halting
nitrix@pluto ~/projects/ni/boot [develop]$ cat test
9:0:8:-1:1:1:8:0:0:113
[9:0:8:-1] # Substracts $9 ('q'), from $0 (stdin), places result in $8 (discard), branch to -1 (halt) when zero (compares equal).
[1:1:8:0] # Equivalent to JMP 0. It substracts $1 from $1, places result in $8 (discard), always branches, to the begining of the program, $0.
[0:113] # DB '0' (garbage) DB 'q' (to compare)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment