diff --git a/consts.c b/consts.c index ce16cb4..348d59a 100644 --- a/consts.c +++ b/consts.c @@ -1,6 +1,6 @@ #ifndef CONSTS #define CONSTS -#define VERSION 6 +#define VERSION 8 #endif /* ifndef CONSTS #define CONSTS diff --git a/fib.asm b/fib.asm new file mode 100644 index 0000000..ca2f81f --- /dev/null +++ b/fib.asm @@ -0,0 +1,177 @@ +// +// version +// + .vers 6 + +// +// execution framework +// +__start: + call _main + call _exit +__stop: + jmp __stop + +// +// Integer readInteger() +// +_readInteger: + asf 0 + rdint + popr + rsf + ret + +// +// void writeInteger(Integer) +// +_writeInteger: + asf 0 + pushl -3 + wrint + rsf + ret + +// +// Character readCharacter() +// +_readCharacter: + asf 0 + rdchr + popr + rsf + ret + +// +// void writeCharacter(Character) +// +_writeCharacter: + asf 0 + pushl -3 + wrchr + rsf + ret + +// +// Integer char2int(Character) +// +_char2int: + asf 0 + pushl -3 + popr + rsf + ret + +// +// Character int2char(Integer) +// +_int2char: + asf 0 + pushl -3 + popr + rsf + ret + +// +// void exit() +// +_exit: + asf 0 + halt + rsf + ret + +// +// void main() +// +_main: + asf 2 + call _readInteger + pushr + popl 0 + pushl 0 + call _fib + drop 1 + pushr + popl 1 + pushl 0 + call _writeInteger + drop 1 + pushc 10 + call _writeCharacter + drop 1 + pushc 102 + call _writeCharacter + drop 1 + pushc 105 + call _writeCharacter + drop 1 + pushc 98 + call _writeCharacter + drop 1 + pushc 58 + call _writeCharacter + drop 1 + pushc 32 + call _writeCharacter + drop 1 + pushl 1 + call _writeInteger + drop 1 + pushc 10 + call _writeCharacter + drop 1 +__0: + rsf + ret + +// +// Integer fib(Integer) +// +_fib: + asf 4 + pushc 0 + popl 0 + pushc 1 + popl 1 + pushc 0 + popl 2 + pushc 1 + popl 3 + pushl -3 + pushc 2 + lt + brf __2 + pushc 1 + popr + jmp __1 + jmp __3 +__2: + jmp __5 +__4: + pushl 0 + pushl 1 + add + popl 2 + pushl 1 + popl 0 + pushl 2 + popl 1 + pushl 3 + pushc 1 + add + popl 3 +__5: + pushl 3 + pushl -3 + lt + brt __4 +__6: + pushl 2 + popr + jmp __1 +__3: +__1: + rsf + ret + diff --git a/fib.bin?inline=false b/fib.bin?inline=false new file mode 100644 index 0000000..da3fc02 Binary files /dev/null and b/fib.bin?inline=false differ diff --git a/njvm.o b/njvm.o index f15b144..6f57e7a 100644 Binary files a/njvm.o and b/njvm.o differ diff --git a/prog.bin b/prog.bin index 666df3c..da3fc02 100644 Binary files a/prog.bin and b/prog.bin differ diff --git a/support.o b/support.o index 83da1f6..b9bac9c 100644 Binary files a/support.o and b/support.o differ