Skip to content

Instantly share code, notes, and snippets.

@crcx
Created April 28, 2017 19:33
Show Gist options
  • Save crcx/ed6e3e035a90a54ec7814d51a8c87428 to your computer and use it in GitHub Desktop.
Save crcx/ed6e3e035a90a54ec7814d51a8c87428 to your computer and use it in GitHub Desktop.
s:to-number
: next
i lica....
r fetch-next
i zr......
i lisuswpu
d 48
i swlimuad
d 10
i poliju..
r next
: check
i dufelieq
d 45
i zr......
i drswdrli
d -1
i swliadre
d 1
: s:to-number
i liswlica
d 1
r check
i liswlica
d 0
r next
i drmure..
:next
lit &fetch-next
call
zret
lit 48
sub
swap
push
swap
lit 10
mul
add
pop
lit &next
jump
:check
dup
fetch
lit 1
eq?
zret
drop
swap
drop
lit -1
swap
lit 1
add
ret
:s:to-number
lit 1
swap
lit &check
call
lit 0
swap
lit &next
call
drop
mul
ret
:to-number:Mod
.data 0
:to-number:Acc
.data 0
:to-number:char>digit
lit 48
sub
ret
:to-number:scale
lit &to-number:Acc
fetch
lit 10
mul
ret
:to-number:convert
lit &fetch-next
call
zret
lit &to-number:char>digit
call
lit &to-number:scale
call
add
lit &to-number:Acc
store
lit &to-number:convert
jump
:to-number:prepare
lit 1
lit &to-number:Mod
store
lit 0
lit &to-number:Acc
store
dup
fetch
lit 45
eq?
zret
drop
lit -1
lit &to-number:Mod
store
lit 1
add
ret
:s:to-number
lit &to-number:prepare
call
lit &to-number:convert
call
drop
lit &to-number:Acc
fetch
lit &to-number:Mod
fetch
mul
ret
@crcx
Copy link
Author

crcx commented Apr 28, 2017

new.muri is the new implementation for the new muri assembler
new.naje is the new implementation for the older naje assembler
old.naje is the previous implementation for the older naje assembler


Muri is a new assembler I wrote yesterday. It allows me to interact closer to the actual instruction set level (as I have to manually pack the instructions and sequence the data elements). Though this is more complex to use, it's a much simpler implementation.

Reading it:

The first column tells Muri what follows.

key used for
i instruction
: labels
d numeric data
s string data
r reference to label

Instructions are packed up to four per location, with the standard caveat that instructions modifying IP must be followed only by nop (the two ..). Instructions are named using the first two characters of their descriptive names from the table below..

0  nop     7  jump   14  gt     21  and
1  lit <v> 8  call   15  fetch  22  or
2  dup     9  ccall  16  store  23  xor
3  drop   10  return 17  add    24  shift
4  swap   11  eq     18  sub    25  zret
5  push   12  neq    19  mul    26  end
6  pop    13  lt     20  divmod

A li (literal) is followed by the value to push in the following cell.


At a higher level:

:next  (nns-nna) fetch-next 0; #48 - swap push swap #10 * + pop next ;
:check (na-na)   dup fetch #45 eq? 0; drop swap drop #-1 swap n:inc ;
:s:to-number   (s-n)     #1 swap check #0 swap next drop * ;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment