diff --git a/src/opcodes.h b/src/opcodes.h index 15a8e65..770d129 100644 --- a/src/opcodes.h +++ b/src/opcodes.h @@ -119,7 +119,7 @@ typedef enum { OP_UINT_TO_REAL, /* utor : dest = src1 as f32 */ OP_ADD_REAL, /* addr : dest = src1 + src2 */ OP_SUB_REAL, /* subr : dest = src1 - src2 */ - OP_MUL_REAL, /* ulr : dest = src1 * src2 */ + OP_MUL_REAL, /* mulr : dest = src1 * src2 */ OP_DIV_REAL, /* divr : dest = src1 / src2 */ OP_JEQ_REAL, /* jeqr : jump to address dest if src1 as real == src2 as real */ OP_JGE_REAL, /* jgtr : jump to address dest if src1 as real >= src2 as real */ diff --git a/test/add.asm b/test/add.asm index e58002f..195b158 100644 --- a/test/add.asm +++ b/test/add.asm @@ -1,8 +1,8 @@ main: - loadi $0 1 ;load 1 into r0 - pushi $0 ;push onto stack - loadi $0 1 ;1 - pushi $0 + lodi $0 1 ;load 1 into r0 + pshi $0 ;push onto stack + lodi $0 1 ;1 + pshi $0 call &add ; call memory location for tag "add" popi $0 ;get value from function call "add" itos $1 $0 ;convert int to string @@ -13,5 +13,5 @@ add: popi $0 ; int a popi $1 ; int b addi $2 $1 $0 ; a + b - pushi $2 - return ; actually do the return + pshi $2 + retn ; actually do the return diff --git a/test/add.lisp b/test/add.lisp new file mode 100644 index 0000000..9c35da9 --- /dev/null +++ b/test/add.lisp @@ -0,0 +1,5 @@ +(defun add (int a int b) + (return (+ a b))) + +(let ((sum (add 1 1))) + (print (itos sum))) diff --git a/test/fib.asm b/test/fib.asm index 335d7a9..14810c7 100644 --- a/test/fib.asm +++ b/test/fib.asm @@ -1,6 +1,6 @@ main: - loadi $0 35 - pushi $0 + lodi $0 35 + pshi $0 call &fib popi $0 itos $1 $0 @@ -8,22 +8,22 @@ main: halt fib: popi $0 - loadi $1 2 - loadi $2 &base_case - jlt $2 $0 $1 - loadi $2 2 + lodi $1 2 + lodi $2 &base_case + jlti $2 $0 $1 + lodi $2 2 subi $4 $0 $3 - pushi $4 + pshi $4 call &fib - load $2 1 + lodi $2 1 subi $4 $0 $3 - pushi $4 + pshi $4 call &fib popi $4 popi $5 addi $6 $5 $4 - pushi $6 - return + pshi $6 + retn base_case: - pushi $0 - return + pshi $0 + retn diff --git a/test/fib.lisp b/test/fib.lisp new file mode 100644 index 0000000..123a13e --- /dev/null +++ b/test/fib.lisp @@ -0,0 +1,7 @@ +(defun fib (int n) + (if (n < 2) + (return n) + (return (+ (fib (- n 2)) + (fib (- n 1)))))) + +(puts (itos (fib 35))) diff --git a/test/fib.zre b/test/fib.zre index 4eb78d1..9f37ba1 100644 --- a/test/fib.zre +++ b/test/fib.zre @@ -1,4 +1,4 @@ -fn fib(n) { +fn fib(int n) { if (n < 2) return n; return fib(n - 2) + fib(n - 1); } diff --git a/test/hello.lisp b/test/hello.lisp new file mode 100644 index 0000000..35d4626 --- /dev/null +++ b/test/hello.lisp @@ -0,0 +1 @@ +(puts "nuqneH 'u'?") diff --git a/test/loop.asm b/test/loop.asm index 1367b61..f76753a 100644 --- a/test/loop.asm +++ b/test/loop.asm @@ -1,20 +1,17 @@ -.memory -.ascii Enter a string: - -.code main: - loadf $0 5.0 - loadi $1 50000 - loadi $2 0 - loadi $3 -1 -loop: - loadf $5 5.0 + lodr $0 5.0 + lodi $1 50000 + lodi $2 0 + lodi $3 -1 +loop_body: + lodr $5 5.0 addr $0 $0 $5 addi $1 $1 $3 - loadu $4 &loop + lodu $4 &loop_body jgei $4 $1 $2 rtou $1 $0 - loadu $5 0 + strs "Enter a string:" + ladu $5 0 puts $5 gets $2 utos $3 $1 diff --git a/test/loop.lisp b/test/loop.lisp new file mode 100644 index 0000000..0ffd116 --- /dev/null +++ b/test/loop.lisp @@ -0,0 +1,9 @@ +(let ((a 5.0)) + (do (i (5000 0 -1)) + (set a (+ a 5.0))) + (let ((b (itou a))) + (puts "Enter a string:") + (let ((user-string (gets))) + (puts (rtos a)) + (puts (utos b)) + (puts user-string)))) diff --git a/test/loop.zre b/test/loop.zre index 92b5382..8c93673 100644 --- a/test/loop.zre +++ b/test/loop.zre @@ -1,8 +1,9 @@ let a = 5.0; do (let i = 50000, 0, -1) { - a += 5.0; + a = a + 5.0; } let b = a as nat; +print("Enter a string:"); let user_string = gets(); print(a.toS()); print(b.toS());