diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..a2eb533 Binary files /dev/null and b/.DS_Store differ diff --git a/GC.c b/GC.c index 8ac480a..7242172 100644 --- a/GC.c +++ b/GC.c @@ -21,7 +21,7 @@ struct sda sda; // Stack struct stack stack; -#define SIZE 10000 +#define SIZE 100000 //Register struct stack reg; diff --git a/bigint/build/bin/testbip b/bigint/build/bin/testbip index a9e294d..66b76a3 100755 Binary files a/bigint/build/bin/testbip and b/bigint/build/bin/testbip differ diff --git a/bigint/build/lib/libbigint.a b/bigint/build/lib/libbigint.a index cf0b02b..9581749 100644 Binary files a/bigint/build/lib/libbigint.a and b/bigint/build/lib/libbigint.a differ diff --git a/bigint/src/libbigint.a b/bigint/src/libbigint.a index cf0b02b..9581749 100644 Binary files a/bigint/src/libbigint.a and b/bigint/src/libbigint.a differ diff --git a/bigint/tst/testbip b/bigint/tst/testbip index a9e294d..66b76a3 100755 Binary files a/bigint/tst/testbip and b/bigint/tst/testbip differ diff --git a/njvm.c b/njvm.c index 55f109d..35e25d7 100644 --- a/njvm.c +++ b/njvm.c @@ -35,7 +35,7 @@ void execute(struct program program) { ObjRef tempObj2; int tempInt; for (i = 0; i < *program.size; ++i) { - if (debug == 1) debugMenu(fp, stack, &debug, i); +// if (debug == 1) debugMenu(fp, stack, &debug, i); switch (program.program[i] >> 24) { case HALT: if (debug == 1) printf("halt\n"); @@ -314,17 +314,17 @@ int main(int argc, char *argv[]) { stack.stack = malloc(SIZE * 1024); // Initialize the registery - int rSize = 1000; + int rSize = 100000; int rCurrent = 0; - StackSlot r[1000]; + StackSlot r[100000]; reg.size = &rSize; reg.current = &rCurrent; reg.stack = r; // Initialize ProgrammSpeicher - int psize = 1000; + int psize = 100000; int saveProgram = 0; - unsigned int p[1000]; + unsigned int p[100000]; program.size = &psize; program.program = p; program.saveProgram = &saveProgram; diff --git a/njvm.o b/njvm.o index 0acc7da..8a1c7b1 100644 Binary files a/njvm.o and b/njvm.o differ diff --git a/programs/matrix.asm b/programs/matrix.asm new file mode 100644 index 0000000..263257d --- /dev/null +++ b/programs/matrix.asm @@ -0,0 +1,778 @@ +// +// version +// + .vers 7 + +// +// 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 writeString(String) +// +_writeString: + asf 1 + pushc 0 + popl 0 + jmp _writeString_L2 +_writeString_L1: + pushl -3 + pushl 0 + getfa + call _writeCharacter + drop 1 + pushl 0 + pushc 1 + add + popl 0 +_writeString_L2: + pushl 0 + pushl -3 + getsz + lt + brt _writeString_L1 + rsf + ret + +// +// Integer gcd(Integer, Integer) +// +_gcd: + asf 1 + jmp __2 +__1: + pushl -4 + pushl -3 + mod + popl 0 + pushl -3 + popl -4 + pushl 0 + popl -3 +__2: + pushl -3 + pushc 0 + ne + brt __1 +__3: + pushl -4 + popr + jmp __0 +__0: + rsf + ret + +// +// record { Integer num; Integer den; } newFraction(Integer, Integer) +// +_newFraction: + asf 4 + pushl -4 + pushc 0 + lt + brf __5 + pushc 0 + pushl -4 + sub + popl 0 + jmp __6 +__5: + pushl -4 + popl 0 +__6: + pushl -3 + pushc 0 + lt + brf __7 + pushc 0 + pushl -3 + sub + popl 1 + jmp __8 +__7: + pushl -3 + popl 1 +__8: + pushl 0 + pushl 1 + call _gcd + drop 2 + pushr + popl 2 + new 2 + popl 3 + pushl -4 + pushc 0 + lt + pushl -3 + pushc 0 + lt + ne + brf __9 + pushl 3 + pushc 0 + pushl 0 + sub + pushl 2 + div + putf 0 + jmp __10 +__9: + pushl 3 + pushl 0 + pushl 2 + div + putf 0 +__10: + pushl 3 + pushl 1 + pushl 2 + div + putf 1 + pushl 3 + popr + jmp __4 +__4: + rsf + ret + +// +// void writeFraction(record { Integer num; Integer den; }) +// +_writeFraction: + asf 0 + pushl -3 + getf 0 + call _writeInteger + drop 1 + pushc 1 + newa + dup + pushc 0 + pushc 47 + putfa + call _writeString + drop 1 + pushl -3 + getf 1 + call _writeInteger + drop 1 +__11: + rsf + ret + +// +// record { Integer num; Integer den; } negFraction(record { Integer num; Integer den; }) +// +_negFraction: + asf 0 + pushc 0 + pushl -3 + getf 0 + sub + pushl -3 + getf 1 + call _newFraction + drop 2 + pushr + popr + jmp __12 +__12: + rsf + ret + +// +// record { Integer num; Integer den; } addFraction(record { Integer num; Integer den; }, record { Integer num; Integer den; }) +// +_addFraction: + asf 0 + pushl -4 + getf 0 + pushl -3 + getf 1 + mul + pushl -3 + getf 0 + pushl -4 + getf 1 + mul + add + pushl -4 + getf 1 + pushl -3 + getf 1 + mul + call _newFraction + drop 2 + pushr + popr + jmp __13 +__13: + rsf + ret + +// +// record { Integer num; Integer den; } subFraction(record { Integer num; Integer den; }, record { Integer num; Integer den; }) +// +_subFraction: + asf 0 + pushl -4 + getf 0 + pushl -3 + getf 1 + mul + pushl -3 + getf 0 + pushl -4 + getf 1 + mul + sub + pushl -4 + getf 1 + pushl -3 + getf 1 + mul + call _newFraction + drop 2 + pushr + popr + jmp __14 +__14: + rsf + ret + +// +// record { Integer num; Integer den; } mulFraction(record { Integer num; Integer den; }, record { Integer num; Integer den; }) +// +_mulFraction: + asf 0 + pushl -4 + getf 0 + pushl -3 + getf 0 + mul + pushl -4 + getf 1 + pushl -3 + getf 1 + mul + call _newFraction + drop 2 + pushr + popr + jmp __15 +__15: + rsf + ret + +// +// record { Integer num; Integer den; } divFraction(record { Integer num; Integer den; }, record { Integer num; Integer den; }) +// +_divFraction: + asf 0 + pushl -4 + getf 0 + pushl -3 + getf 1 + mul + pushl -4 + getf 1 + pushl -3 + getf 0 + mul + call _newFraction + drop 2 + pushr + popr + jmp __16 +__16: + rsf + ret + +// +// Fraction[][] newMatrix(record { Integer num; Integer den; }, record { Integer num; Integer den; }, record { Integer num; Integer den; }, record { Integer num; Integer den; }) +// +_newMatrix: + asf 1 + pushc 2 + newa + popl 0 + pushl 0 + pushc 0 + pushc 2 + newa + putfa + pushl 0 + pushc 1 + pushc 2 + newa + putfa + pushl 0 + pushc 0 + getfa + pushc 0 + pushl -6 + putfa + pushl 0 + pushc 0 + getfa + pushc 1 + pushl -5 + putfa + pushl 0 + pushc 1 + getfa + pushc 0 + pushl -4 + putfa + pushl 0 + pushc 1 + getfa + pushc 1 + pushl -3 + putfa + pushl 0 + popr + jmp __17 +__17: + rsf + ret + +// +// void writeMatrix(Fraction[][]) +// +_writeMatrix: + asf 2 + pushc 0 + popl 0 + jmp __20 +__19: + pushc 0 + popl 1 + jmp __23 +__22: + pushl -3 + pushl 0 + getfa + pushl 1 + getfa + call _writeFraction + drop 1 + pushc 2 + newa + dup + pushc 0 + pushc 32 + putfa + dup + pushc 1 + pushc 32 + putfa + call _writeString + drop 1 + pushl 1 + pushc 1 + add + popl 1 +__23: + pushl 1 + pushl -3 + pushl 0 + getfa + getsz + lt + brt __22 +__24: + pushc 1 + newa + dup + pushc 0 + pushc 10 + putfa + call _writeString + drop 1 + pushl 0 + pushc 1 + add + popl 0 +__20: + pushl 0 + pushl -3 + getsz + lt + brt __19 +__21: + pushc 1 + newa + dup + pushc 0 + pushc 10 + putfa + call _writeString + drop 1 +__18: + rsf + ret + +// +// Fraction[][] invertMatrix(Fraction[][]) +// +_invertMatrix: + asf 1 + pushl -3 + pushc 0 + getfa + pushc 0 + getfa + pushl -3 + pushc 1 + getfa + pushc 1 + getfa + call _mulFraction + drop 2 + pushr + pushl -3 + pushc 0 + getfa + pushc 1 + getfa + pushl -3 + pushc 1 + getfa + pushc 0 + getfa + call _mulFraction + drop 2 + pushr + call _subFraction + drop 2 + pushr + popl 0 + pushl 0 + getf 0 + pushc 0 + eq + brf __26 + pushc 33 + newa + dup + pushc 0 + pushc 101 + putfa + dup + pushc 1 + pushc 114 + putfa + dup + pushc 2 + pushc 114 + putfa + dup + pushc 3 + pushc 111 + putfa + dup + pushc 4 + pushc 114 + putfa + dup + pushc 5 + pushc 58 + putfa + dup + pushc 6 + pushc 32 + putfa + dup + pushc 7 + pushc 109 + putfa + dup + pushc 8 + pushc 97 + putfa + dup + pushc 9 + pushc 116 + putfa + dup + pushc 10 + pushc 114 + putfa + dup + pushc 11 + pushc 105 + putfa + dup + pushc 12 + pushc 120 + putfa + dup + pushc 13 + pushc 32 + putfa + dup + pushc 14 + pushc 99 + putfa + dup + pushc 15 + pushc 97 + putfa + dup + pushc 16 + pushc 110 + putfa + dup + pushc 17 + pushc 110 + putfa + dup + pushc 18 + pushc 111 + putfa + dup + pushc 19 + pushc 116 + putfa + dup + pushc 20 + pushc 32 + putfa + dup + pushc 21 + pushc 98 + putfa + dup + pushc 22 + pushc 101 + putfa + dup + pushc 23 + pushc 32 + putfa + dup + pushc 24 + pushc 105 + putfa + dup + pushc 25 + pushc 110 + putfa + dup + pushc 26 + pushc 118 + putfa + dup + pushc 27 + pushc 101 + putfa + dup + pushc 28 + pushc 114 + putfa + dup + pushc 29 + pushc 116 + putfa + dup + pushc 30 + pushc 101 + putfa + dup + pushc 31 + pushc 100 + putfa + dup + pushc 32 + pushc 10 + putfa + call _writeString + drop 1 + call _exit +__26: + pushl -3 + pushc 1 + getfa + pushc 1 + getfa + pushl 0 + call _divFraction + drop 2 + pushr + pushl -3 + pushc 0 + getfa + pushc 1 + getfa + call _negFraction + drop 1 + pushr + pushl 0 + call _divFraction + drop 2 + pushr + pushl -3 + pushc 1 + getfa + pushc 0 + getfa + call _negFraction + drop 1 + pushr + pushl 0 + call _divFraction + drop 2 + pushr + pushl -3 + pushc 0 + getfa + pushc 0 + getfa + pushl 0 + call _divFraction + drop 2 + pushr + call _newMatrix + drop 4 + pushr + popr + jmp __25 +__25: + rsf + ret + +// +// void main() +// +_main: + asf 3 + pushc 1 + newa + dup + pushc 0 + pushc 10 + putfa + call _writeString + drop 1 + pushc 7 + pushc 1 + call _newFraction + drop 2 + pushr + pushc 4 + pushc 1 + call _newFraction + drop 2 + pushr + pushc 6 + pushc 1 + call _newFraction + drop 2 + pushr + pushc 5 + pushc 1 + call _newFraction + drop 2 + pushr + call _newMatrix + drop 4 + pushr + popl 0 + pushl 0 + call _writeMatrix + drop 1 + pushl 0 + call _invertMatrix + drop 1 + pushr + popl 1 + pushl 1 + call _writeMatrix + drop 1 + pushl 1 + call _invertMatrix + drop 1 + pushr + popl 2 + pushl 2 + call _writeMatrix + drop 1 +__27: + rsf + ret