Compare commits

..

23 Commits

Author SHA1 Message Date
240e93a90f +++ 2024-01-28 23:20:45 +01:00
bc41dcda4a --- 2024-01-28 23:15:34 +01:00
f62030772a ,,, 2024-01-28 23:10:28 +01:00
43663714ca ... 2024-01-28 23:06:11 +01:00
38bfd5c7d9 add heap size 2024-01-28 23:02:03 +01:00
nilspolek
f348174229 gc 2024-01-28 22:29:20 +01:00
nilspolek
bc8a037a30 gc 2024-01-28 22:26:50 +01:00
nilspolek
958c383f85 changed objref to prevent bugs 2024-01-28 10:30:39 +01:00
nilspolek
f3829559d4 null problems are now not more 2024-01-28 00:14:19 +01:00
nilspolek
9155216fd2 now breakpoints are possible 2024-01-27 23:29:33 +01:00
nilspolek
b6320ecba7 updated the test 2024-01-27 23:21:18 +01:00
nilspolek
3bd8b9ac20 updated the test 2024-01-27 23:20:25 +01:00
root
147415beef s 2024-01-27 22:14:18 +00:00
nilspolek
5fb42ff984 updated the test 2024-01-27 23:09:29 +01:00
nilspolek
d7bb53687d updated the test 2024-01-27 23:08:21 +01:00
root
ee27de7481 factor.asm 2024-01-27 22:01:18 +00:00
root
eaab6ab023 s 2024-01-27 21:55:35 +00:00
nilspolek
38f06b1575 updated the test 2024-01-27 22:52:29 +01:00
nilspolek
6ebc065a7a added a method for testing arrays 2024-01-27 22:43:34 +01:00
nilspolek
8c45b02769 added njvm2 2024-01-27 21:19:57 +01:00
nilspolek
4cc117fdd4 added tests 2024-01-27 21:18:34 +01:00
nilspolek
49e4911238 added tests 2024-01-27 21:17:06 +01:00
nilspolek
21c1f8fee6 made some updates 2024-01-27 20:53:05 +01:00
74 changed files with 24214 additions and 56 deletions

BIN
.DS_Store vendored Normal file

Binary file not shown.

2
.gitignore vendored
View File

@@ -3,5 +3,3 @@ cmake-build-debug
njvm njvm
njvm.dSYM njvm.dSYM
njvm.exe njvm.exe
njvm2
test

View File

@@ -5,7 +5,8 @@ set(CMAKE_C_STANDARD 99)
add_compile_options(-g -Wall -pedantic) add_compile_options(-g -Wall -pedantic)
add_executable(njvm njvm.c) add_executable(njvm njvm.c
njvm.h)
# Include directories for njvm executable # Include directories for njvm executable
target_include_directories(njvm PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/bigint/build/include) target_include_directories(njvm PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/bigint/build/include)
@@ -13,7 +14,9 @@ target_include_directories(njvm PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/bigint/build
# Add the library # Add the library
add_library(bigint STATIC ${CMAKE_SOURCE_DIR}/bigint/src/bigint.c add_library(bigint STATIC ${CMAKE_SOURCE_DIR}/bigint/src/bigint.c
support.c support.c
GC.c) GC.c
heap.c
heap.h)
# Include directories for the bigint library # Include directories for the bigint library
target_include_directories(bigint PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/bigint/build/include) target_include_directories(bigint PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/bigint/build/include)

2
GC.c
View File

@@ -21,7 +21,7 @@ struct sda sda;
// Stack // Stack
struct stack stack; struct stack stack;
#define SIZE 10000 #define SIZE 1000;
//Register //Register
struct stack reg; struct stack reg;

1
SDA.c
View File

@@ -15,6 +15,7 @@ ObjRef getSDA(int i, struct sda s) {
} }
void setSDA(int point, ObjRef val, struct sda s) { void setSDA(int point, ObjRef val, struct sda s) {
if (val == NULL) perror("Value is null");
s.sda[point] = val; s.sda[point] = val;
} }

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -29,11 +29,14 @@ void inspect(struct stack s, int fp){
void list(void){ void list(void){
//todo //todo
} }
void breakpoint(void){ void breakpoint(int *bp){
//todo printf("BREAKPOINT: ");
char input[20];
fgets(input,20,stdin);
*bp = atoi(input);
} }
void debugMenu(int fp, struct stack stack, int* debug, int point){ void debugMenu(int fp, struct stack stack, int* debug, int point, int* bp){
char input[20]; char input[20];
while (true) { while (true) {
printf("DEBUG(%i): inspect, list, breakpoint, run, step, quit?",point); printf("DEBUG(%i): inspect, list, breakpoint, run, step, quit?",point);
@@ -41,7 +44,7 @@ void debugMenu(int fp, struct stack stack, int* debug, int point){
printf("%s",input); printf("%s",input);
if(input[0] == 'i') {inspect(stack,fp);} if(input[0] == 'i') {inspect(stack,fp);}
if(input[0] == 'l') list(); if(input[0] == 'l') list();
if(input[0] == 'b') breakpoint(); if(input[0] == 'b') breakpoint(bp);
if(input[0] == 's') break; if(input[0] == 's') break;
if(input[0] == 'r') {*debug = 0; break;}; if(input[0] == 'r') {*debug = 0; break;};
if(input[0] == 'q') exit(0); if(input[0] == 'q') exit(0);

8301
factor.asm Normal file

File diff suppressed because it is too large Load Diff

BIN
factor.bin Normal file

Binary file not shown.

33
heap.c Normal file
View File

@@ -0,0 +1,33 @@
//
// Created by Elias Bennour on 28.01.24.
//
#ifndef HEAP
#define HEAP
#include <stdlib.h>
#include <stdio.h>
int maxHeapSize = 8192 * 1024;
void* my_malloc(size_t size) {
static size_t total_allocated = 0;
if (total_allocated + size > maxHeapSize) {
perror("Memory limit exceeded\n");
exit(1);
}
void* ptr = malloc(size);
if (ptr != NULL) {
total_allocated += size;
}
return ptr;
}
void initHeap(int size) {
maxHeapSize = size;
}
#endif //NINJA_NJVM_H

12
heap.h Normal file
View File

@@ -0,0 +1,12 @@
//
// Created by Elias Bennour on 28.01.24.
//
#ifndef NINJA_HEAP_H
#define NINJA_HEAP_H
#include <stdlib.h>
void* my_malloc(size_t size);
#endif //NINJA_HEAP_H

778
matinv.asm Normal file
View File

@@ -0,0 +1,778 @@
//
// version
//
.vers 8
//
// 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

BIN
matinv.bin Normal file

Binary file not shown.

146
matinv.nj Normal file
View File

@@ -0,0 +1,146 @@
//
// matinv.nj -- invert 2x2 matrices of fractions
//
//--------------------------------------------------------------
// greatest common divisor
Integer gcd(Integer a, Integer b) {
local Integer h;
while (b != 0) {
h = a % b;
a = b;
b = h;
}
return a;
}
//--------------------------------------------------------------
// fractions
type Fraction = record {
Integer num;
Integer den;
};
Fraction newFraction(Integer num, Integer den) {
local Integer n;
local Integer d;
local Integer g;
local Fraction r;
if (num < 0) {
n = -num;
} else {
n = num;
}
if (den < 0) {
d = -den;
} else {
d = den;
}
g = gcd(n, d);
r = new(Fraction);
if ((num < 0) != (den < 0)) {
r.num = -n / g;
} else {
r.num = n / g;
}
r.den = d / g;
return r;
}
void writeFraction(Fraction f) {
writeInteger(f.num);
writeString("/");
writeInteger(f.den);
}
Fraction negFraction(Fraction f) {
return newFraction(-f.num, f.den);
}
Fraction addFraction(Fraction f1, Fraction f2) {
return newFraction(f1.num * f2.den + f2.num * f1.den, f1.den * f2.den);
}
Fraction subFraction(Fraction f1, Fraction f2) {
return newFraction(f1.num * f2.den - f2.num * f1.den, f1.den * f2.den);
}
Fraction mulFraction(Fraction f1, Fraction f2) {
return newFraction(f1.num * f2.num, f1.den * f2.den);
}
Fraction divFraction(Fraction f1, Fraction f2) {
return newFraction(f1.num * f2.den, f1.den * f2.num);
}
//--------------------------------------------------------------
// 2x2 matrices of fractions
type Matrix = Fraction[][];
Matrix newMatrix(Fraction a00, Fraction a01,
Fraction a10, Fraction a11) {
local Matrix m;
m = new(Fraction[2][]);
m[0] = new(Fraction[2]);
m[1] = new(Fraction[2]);
m[0][0] = a00;
m[0][1] = a01;
m[1][0] = a10;
m[1][1] = a11;
return m;
}
void writeMatrix(Matrix m) {
local Integer i;
local Integer j;
i = 0;
while (i < sizeof(m)) {
j = 0;
while (j < sizeof(m[i])) {
writeFraction(m[i][j]);
writeString(" ");
j = j + 1;
}
writeString("\n");
i = i + 1;
}
writeString("\n");
}
Matrix invertMatrix(Matrix m) {
local Fraction det;
det = subFraction(mulFraction(m[0][0], m[1][1]),
mulFraction(m[0][1], m[1][0]));
if (det.num == 0) {
writeString("error: matrix cannot be inverted\n");
exit();
}
return newMatrix(
divFraction(m[1][1], det), divFraction(negFraction(m[0][1]), det),
divFraction(negFraction(m[1][0]), det), divFraction(m[0][0], det)
);
}
//--------------------------------------------------------------
void main() {
local Matrix matrix;
local Matrix result1;
local Matrix result2;
writeString("\n");
matrix = newMatrix(
newFraction(7, 1), newFraction(4, 1),
newFraction(6, 1), newFraction(5, 1)
);
writeMatrix(matrix);
result1 = invertMatrix(matrix);
writeMatrix(result1);
result2 = invertMatrix(result1);
writeMatrix(result2);
}

BIN
nja/nja8l Executable file

Binary file not shown.

BIN
njc/njc8

Binary file not shown.

11070
njlisp.asm Normal file

File diff suppressed because it is too large Load Diff

BIN
njlisp.bin Normal file

Binary file not shown.

2580
njlisp.nj Normal file

File diff suppressed because it is too large Load Diff

51
njvm.c
View File

@@ -1,3 +1,6 @@
#ifndef NJVM
#define NJVM
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
@@ -9,6 +12,7 @@
#include "bigint.h" #include "bigint.h"
#include "record.c" #include "record.c"
#include "GC.c" #include "GC.c"
#include "heap.c"
// Debug // Debug
int debug = 0; int debug = 0;
@@ -16,7 +20,6 @@ int debug = 0;
// Program // Program
struct program program; struct program program;
unsigned fp; unsigned fp;
void version(void) { void version(void) {
@@ -28,6 +31,7 @@ void help(void) {
} }
void execute(struct program program) { void execute(struct program program) {
int bp = -1;
int i; int i;
char charInput; char charInput;
StackSlot tempSlot; StackSlot tempSlot;
@@ -35,7 +39,8 @@ void execute(struct program program) {
ObjRef tempObj2; ObjRef tempObj2;
int tempInt; int tempInt;
for (i = 0; i < *program.size; ++i) { for (i = 0; i < *program.size; ++i) {
if (debug == 1) debugMenu(fp, stack, &debug, i); if (debug == 1 || bp == i) debugMenu(fp, stack, &debug, i, &bp);
if(debug == 1) printf("(%i)",i);
switch (program.program[i] >> 24) { switch (program.program[i] >> 24) {
case HALT: case HALT:
if (debug == 1) printf("halt\n"); if (debug == 1) printf("halt\n");
@@ -229,42 +234,42 @@ void execute(struct program program) {
push(stack, stackSlotWithObjRef(tempObj)); push(stack, stackSlotWithObjRef(tempObj));
break; break;
case POPR: case POPR:
if (debug == 1) printf("popr"); if (debug == 1) printf("popr\n");
push(reg, pop(stack)); push(reg, pop(stack));
break; break;
case PUSHR: case PUSHR:
if (debug == 1) printf("pushr"); if (debug == 1) printf("pushr\n");
push(stack, pop(reg)); push(stack, pop(reg));
break; break;
case NEW: case NEW:
if (debug == 1) printf("new"); if (debug == 1) printf("new\t%i\n", SIGN_EXTEND(IMMEDIATE(program.program[i])));
push(stack, stackSlotWithObjRef(newRecord(SIGN_EXTEND(IMMEDIATE(program.program[i]))))); push(stack, stackSlotWithObjRef(newRecord(SIGN_EXTEND(IMMEDIATE(program.program[i])))));
break; break;
case GETF: case GETF:
if (debug == 1) printf("getf"); if (debug == 1) printf("getf\n");
tempObj = pop(stack).u.objRef; tempObj = pop(stack).u.objRef;
push(stack, stackSlotWithObjRef(getField(tempObj,SIGN_EXTEND(IMMEDIATE(program.program[i]))))); push(stack, stackSlotWithObjRef(getField(tempObj,SIGN_EXTEND(IMMEDIATE(program.program[i])))));
break; break;
case PUTF: case PUTF:
if (debug == 1) printf("putf"); if (debug == 1) printf("putf\t%i\n", SIGN_EXTEND(IMMEDIATE(program.program[i])));
tempObj = pop(stack).u.objRef; tempObj = pop(stack).u.objRef;
tempObj2 = pop(stack).u.objRef; tempObj2 = pop(stack).u.objRef;
setField(tempObj2, SIGN_EXTEND(IMMEDIATE(program.program[i])),tempObj); setField(tempObj2, SIGN_EXTEND(IMMEDIATE(program.program[i])),tempObj);
break; break;
case NEWA: case NEWA:
if(debug == 1) printf("newa"); if(debug == 1) printf("newa\n");
bip.op1 = pop(stack).u.objRef; bip.op1 = pop(stack).u.objRef;
push(stack, stackSlotWithObjRef(newRecord(bigToInt()))); push(stack, stackSlotWithObjRef(newRecord(bigToInt())));
break; break;
case GETFA: case GETFA:
if(debug == 1) printf("getfa"); if(debug == 1) printf("getfa\n");
bip.op1 = pop(stack).u.objRef; bip.op1 = pop(stack).u.objRef;
tempInt = bigToInt(); tempInt = bigToInt();
tempObj = pop(stack).u.objRef; tempObj = pop(stack).u.objRef;
push(stack, stackSlotWithObjRef(getField(tempObj,bigToInt()))); push(stack, stackSlotWithObjRef(getField(tempObj,bigToInt())));
break; break;
case PUTFA: case PUTFA:
if (debug == 1) printf("putfa"); if (debug == 1) printf("putfa\n");
tempObj = pop(stack).u.objRef; // Value tempObj = pop(stack).u.objRef; // Value
tempObj2 = pop(stack).u.objRef; // Index tempObj2 = pop(stack).u.objRef; // Index
bip.op1 = tempObj2; bip.op1 = tempObj2;
@@ -272,24 +277,24 @@ void execute(struct program program) {
setField(pop(stack).u.objRef, tempInt,tempObj); setField(pop(stack).u.objRef, tempInt,tempObj);
break; break;
case GETSZ: case GETSZ:
if (debug == 1) printf("getsz"); if (debug == 1) printf("getsz\n");
tempObj = pop(stack).u.objRef; tempObj = pop(stack).u.objRef;
if(IS_PRIMITIVE(tempObj)) bigFromInt(-1); if(IS_PRIMITIVE(tempObj)) bigFromInt(-1);
else bigFromInt(GET_ELEMENT_COUNT(tempObj)); else bigFromInt(GET_ELEMENT_COUNT(tempObj));
push(stack, stackSlotWithObjRef(bip.res)); push(stack, stackSlotWithObjRef(bip.res));
break; break;
case PUSHN: case PUSHN:
if (debug == 1) printf("pushn"); if (debug == 1) printf("pushn\n");
push(stack, stackSlotWithObjRef(NULL)); push(stack, stackSlotWithObjRef(NULL));
break; break;
case REFEQ: case REFEQ:
if (debug == 1) printf("refeq"); if (debug == 1) printf("refeq\n");
if(pop(stack).u.objRef == pop(stack).u.objRef) bigFromInt(true); if(pop(stack).u.objRef == pop(stack).u.objRef) bigFromInt(true);
else bigFromInt(false); else bigFromInt(false);
push(stack, stackSlotWithObjRef(bip.res)); push(stack, stackSlotWithObjRef(bip.res));
break; break;
case REFNE: case REFNE:
if (debug == 1) printf("refeq"); if (debug == 1) printf("refeq\n");
if(pop(stack).u.objRef != pop(stack).u.objRef) bigFromInt(true); if(pop(stack).u.objRef != pop(stack).u.objRef) bigFromInt(true);
else bigFromInt(false); else bigFromInt(false);
push(stack, stackSlotWithObjRef(bip.res)); push(stack, stackSlotWithObjRef(bip.res));
@@ -304,26 +309,28 @@ void tests(void) {
} }
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
// Initialize the Stack // Initialize the Stack
int size = SIZE; int size = SIZE;
int current = 0; int current = 0;
stack.size = &size; stack.size = &size;
stack.current = &current; stack.current = &current;
stack.stack = malloc(SIZE * 1024); stack.stack = malloc(size * 1024);
if (stack.stack == NULL) {
perror("malloc");
}
// Initialize the registery // Initialize the registery
int rSize = 1000; int rSize = 100000;
int rCurrent = 0; int rCurrent = 0;
StackSlot r[1000]; StackSlot r[100000];
reg.size = &rSize; reg.size = &rSize;
reg.current = &rCurrent; reg.current = &rCurrent;
reg.stack = r; reg.stack = r;
// Initialize ProgrammSpeicher // Initialize ProgrammSpeicher
int psize = 1000; int psize = 100000;
int saveProgram = 0; int saveProgram = 0;
unsigned int p[1000]; unsigned int p[100000];
program.size = &psize; program.size = &psize;
program.program = p; program.program = p;
program.saveProgram = &saveProgram; program.saveProgram = &saveProgram;
@@ -346,7 +353,7 @@ int main(int argc, char *argv[]) {
// TODO: implement stack size // TODO: implement stack size
} else if (strcmp(argv[i], "--heap") == 0) { } else if (strcmp(argv[i], "--heap") == 0) {
i++; i++;
// TODO: implement heap size initHeap(atoi(argv[i]));
} else if (strcmp(argv[i], "--gcpurge") == 0) { } else if (strcmp(argv[i], "--gcpurge") == 0) {
// TODO: implement gcpurge // TODO: implement gcpurge
} else { } else {
@@ -373,3 +380,5 @@ int main(int argc, char *argv[]) {
return 1; return 1;
} }
} }
#endif /* ifndef NJVM */

BIN
njvm.o

Binary file not shown.

BIN
njvm2 Executable file

Binary file not shown.

BIN
prog.bin

Binary file not shown.

778
programs/matrix.asm Normal file
View File

@@ -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

View File

@@ -9,7 +9,7 @@ ObjRef newRecord(int size){
ObjRef record; ObjRef record;
unsigned int objSize; unsigned int objSize;
objSize = sizeof(*record) + (size * sizeof(void *)); objSize = sizeof(*record) + (size * sizeof(void *));
if((record = malloc(objSize)) == NULL){ if((record = my_malloc(objSize)) == NULL){
perror("malloc"); perror("malloc");
} }
record->size = MSB; record->size = MSB;
@@ -20,28 +20,35 @@ ObjRef newRecord(int size){
return record; return record;
} }
int getSize(ObjRef arr){ int getSize(ObjRef arr){
if(arr == NULL) return 0;
return GET_ELEMENT_COUNT(arr); return GET_ELEMENT_COUNT(arr);
} }
ObjRef getField(ObjRef arr, int point){ ObjRef getField(ObjRef arr, int point){
if(arr == NULL) perror("Record is null");
if(0 > point || point > getSize(arr)){ if(0 > point || point > getSize(arr)){
printf("Index %i out of bounds for length %i\n",point, getSize(arr)); printf("Index %i out of bounds for length %i\n",point, getSize(arr));
} }
return *(ObjRef *)GET_REFS_PTR(arr)[point]->data; return *(ObjRef *)GET_REFS_PTR(arr)[point]->data;
} }
void setField(ObjRef arr, int point, ObjRef value){ void setField(ObjRef arr, int point, ObjRef value){
if(0 > point || point > getSize(arr)){ bool isNull = false;
if(value == NULL) isNull = true;
if(0 > point || point >= getSize(arr)){
printf("Index %i out of bounds for length %i\n",point, getSize(arr)); printf("Index %i out of bounds for length %i\n",point, getSize(arr));
exit(EXIT_FAILURE);
} }
if(IS_PRIMITIVE(value)){ if(arr == NULL) perror("Record is null");
// printf("Size of value is %i\n", value->size); if(IS_PRIMITIVE(arr)) perror("Record is a primitive");
int size = value->size; int size;
GET_REFS_PTR(arr)[point] = malloc(size); if (isNull) size = sizeof(void *);
GET_REFS_PTR(arr)[point]->size = size; else {
}else{ if (IS_PRIMITIVE(value))
int size = sizeof(*value) + (GET_ELEMENT_COUNT(value) * sizeof(void *)); size = value->size;
GET_REFS_PTR(arr)[point] = malloc(size); else
GET_REFS_PTR(arr)[point] ->size = size; size = sizeof(*value) + (GET_ELEMENT_COUNT(value) * sizeof(void *));
} }
if((GET_REFS_PTR(arr)[point] = my_malloc(size)) == NULL) perror("malloc");
GET_REFS_PTR(arr)[point] ->size = size;
* (ObjRef *)GET_REFS_PTR(arr)[point]->data = value; * (ObjRef *)GET_REFS_PTR(arr)[point]->data = value;
} }

View File

@@ -8,9 +8,6 @@
#include <stdlib.h> #include <stdlib.h>
#include "stackslot.c" #include "stackslot.c"
struct stack { struct stack {
int* size; int* size;
int* current; int* current;
@@ -26,11 +23,13 @@ void printStack(struct stack stack, int fp) {
printf("Stack\nSize:\t\t%i\nCurrent:\t%i\n", *stack.size, *stack.current); printf("Stack\nSize:\t\t%i\nCurrent:\t%i\n", *stack.size, *stack.current);
for (int i = *stack.current -1; i >= 0; --i) { for (int i = *stack.current -1; i >= 0; --i) {
printf("%i\t",i); printf("%i\t",i);
if(stack.stack[i].u.objRef == NULL) printf("|NULL|");
else
if(stack.stack[i].isObjRef){ if(stack.stack[i].isObjRef){
printf("|%p|", (void *)stack.stack[i].u.objRef); printf("|%p|", (void *)stack.stack[i].u.objRef);
if(stack.stack[i].u.objRef->size == sizeof(int)) if(stack.stack[i].u.objRef->size == sizeof(int))
printf("(%i)",*(int *)stack.stack[i].u.objRef->data); printf("(%i)",*(int *)stack.stack[i].u.objRef->data);
}else { }else {
printf("|%i|", getIntValfromStackSlot(stack.stack[i])); printf("|%i|", getIntValfromStackSlot(stack.stack[i]));
} }
if(fp == i) printf("<-\tFP\n"); if(fp == i) printf("<-\tFP\n");

View File

@@ -1,14 +1,13 @@
#ifndef STACKSLOT
#define STACKSLOT
#include <stdbool.h> #include <stdbool.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include "objref.c"
#include "heap.h"
#ifndef STACKSLOT
#define STACKSLOT
typedef int Object; typedef int Object;
typedef struct ObjRef{
unsigned int size;
unsigned char data[1];
} *ObjRef;
typedef struct { typedef struct {
bool isObjRef; bool isObjRef;
@@ -21,7 +20,7 @@ typedef struct {
ObjRef getIntObj(int val) { ObjRef getIntObj(int val) {
ObjRef intObject; ObjRef intObject;
unsigned int objSize = sizeof(ObjRef) + sizeof(int); unsigned int objSize = sizeof(ObjRef) + sizeof(int);
if ((intObject = malloc(objSize)) == NULL) { if ((intObject = my_malloc(objSize)) == NULL) {
perror("malloc"); perror("malloc");
} }
*(int *) intObject->data = val; *(int *) intObject->data = val;
@@ -30,6 +29,7 @@ ObjRef getIntObj(int val) {
} }
int getValFromIntObj(ObjRef iref) { int getValFromIntObj(ObjRef iref) {
if (iref == NULL) perror("ObjRef is null");
return *(int *) iref->data; return *(int *) iref->data;
} }
@@ -41,13 +41,15 @@ int getIntValfromStackSlot(StackSlot s) {
} }
void setValIntObj(ObjRef iref, int val) { void setValIntObj(ObjRef iref, int val) {
if (iref == NULL) perror("ObjRef is null");
iref->size = sizeof(int)+sizeof(ObjRef); iref->size = sizeof(int)+sizeof(ObjRef);
*(int *) iref->data = val; *(int *) iref->data = val;
} }
StackSlot stackSlotWithObjRef(ObjRef val) { StackSlot stackSlotWithObjRef(ObjRef val) {
StackSlot *stackSlot; StackSlot *stackSlot;
stackSlot = malloc(sizeof(StackSlot)); stackSlot = my_malloc(sizeof(StackSlot));
if(stackSlot == NULL) perror("malloc");
stackSlot->isObjRef = true; stackSlot->isObjRef = true;
stackSlot->u.objRef = val; stackSlot->u.objRef = val;
return *stackSlot; return *stackSlot;
@@ -55,7 +57,8 @@ StackSlot stackSlotWithObjRef(ObjRef val) {
StackSlot stackSlotWitchNumber(int val) { StackSlot stackSlotWitchNumber(int val) {
StackSlot *stackSlot; StackSlot *stackSlot;
stackSlot = malloc(sizeof(StackSlot)); stackSlot = my_malloc(sizeof(StackSlot));
if(stackSlot == NULL) perror("malloc");
stackSlot->isObjRef = false; stackSlot->isObjRef = false;
stackSlot->u.number = val; stackSlot->u.number = val;
return *stackSlot; return *stackSlot;

View File

@@ -1,9 +1,9 @@
#include "support.h" #include "support.h"
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include "objref.c" #include "objref.c"
#include "heap.h"
void fatalError(char *msg){ void fatalError(char *msg){
printf("Fatal error: %s\n", msg); printf("Fatal error: %s\n", msg);
@@ -13,7 +13,7 @@ void fatalError(char *msg){
void * newPrimObject(int dataSize) { void * newPrimObject(int dataSize) {
ObjRef bigObjRef; ObjRef bigObjRef;
bigObjRef = malloc(sizeof(unsigned int) + bigObjRef = my_malloc(sizeof(unsigned int) +
dataSize * sizeof(unsigned char)); dataSize * sizeof(unsigned char));
if (bigObjRef == NULL) { if (bigObjRef == NULL) {
fatalError("newPrimObject() got no memory"); fatalError("newPrimObject() got no memory");

BIN
support.o

Binary file not shown.

3
test.nj Normal file
View File

@@ -0,0 +1,3 @@
void main(){
}

BIN
test/.DS_Store vendored Normal file

Binary file not shown.

BIN
test/tests/1.bin Normal file

Binary file not shown.

BIN
test/tests/10.bin Normal file

Binary file not shown.

BIN
test/tests/11.bin Normal file

Binary file not shown.

BIN
test/tests/12.bin Normal file

Binary file not shown.

BIN
test/tests/13.bin Normal file

Binary file not shown.

BIN
test/tests/14.bin Normal file

Binary file not shown.

BIN
test/tests/15.bin Normal file

Binary file not shown.

BIN
test/tests/2.bin Normal file

Binary file not shown.

BIN
test/tests/3.bin Normal file

Binary file not shown.

BIN
test/tests/4.bin Normal file

Binary file not shown.

BIN
test/tests/5.bin Normal file

Binary file not shown.

BIN
test/tests/6.bin Normal file

Binary file not shown.

BIN
test/tests/7.bin Normal file

Binary file not shown.

BIN
test/tests/8.bin Normal file

Binary file not shown.

BIN
test/tests/9.bin Normal file

Binary file not shown.

18
test/tests/arrTest.asm Normal file
View File

@@ -0,0 +1,18 @@
new 3
popg 0
pushg 0
pushc 10
putf 0
pushg 0
pushc 11
putf 1
pushg 0
getf 0
pushg 0
getf 1
add
wrint
halt
// Sollte 10 + 11 ergeben

View File

@@ -0,0 +1,13 @@
asf 5
pushc 11
call x
wrint
rsf
halt
x:
asf 3
pushc 22
wrint
rsf

View File

@@ -0,0 +1,125 @@
//
// 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
//
// void main()
//
_main:
asf 0
pushc 4421
pushc 5743
mul
pushc 7699
mul
call _writeInteger
drop 1
__0:
rsf
ret

View File

@@ -0,0 +1,5 @@
pushc 5
pushc 4
add
wrint
halt

View File

@@ -0,0 +1,5 @@
pushc 5
pushc 4
div
wrint
halt

View File

@@ -0,0 +1,5 @@
pushc 5
pushc 4
mod
wrint
halt

View File

@@ -0,0 +1,5 @@
pushc 5
pushc 4
mul
wrint
halt

View File

@@ -0,0 +1,5 @@
pushc 5
pushc 4
sub
wrint
halt

16
test/tests/brfTest1.asm Normal file
View File

@@ -0,0 +1,16 @@
pushc 3
pushc 4
eq
brf L1
pushc 4
L1:
pushc 7
wrint
pushc 10
wrchr
halt

17
test/tests/brfTest2.asm Normal file
View File

@@ -0,0 +1,17 @@
pushc 4
pushc 4
eq
brf L1
pushc 6
wrint
pushc 10
wrchr
halt
L1:
pushc 7
wrint
pushc 10
wrchr
halt

19
test/tests/brtTest1.asm Normal file
View File

@@ -0,0 +1,19 @@
pushc 3
pushc 4
eq
brt L1
pushc 5
wrint
pushc 10
wrchr
halt
L1:
pushc 7
wrint
pushc 10
wrchr
halt

17
test/tests/brtTest2.asm Normal file
View File

@@ -0,0 +1,17 @@
pushc 4
pushc 4
eq
brt L1
pushc 6
wrint
pushc 10
wrchr
halt
L1:
pushc 7
wrint
pushc 10
wrchr
halt

15
test/tests/equalsTest.asm Normal file
View File

@@ -0,0 +1,15 @@
pushc 3
pushc 4
eq
wrint
pushc 10
wrchr
pushc 6
pushc 6
eq
wrint
pushc 10
wrchr
halt

View File

@@ -0,0 +1,24 @@
pushc 3
pushc 4
ge
wrint
pushc 10
wrchr
pushc 8
pushc 4
ge
wrint
pushc 10
wrchr
pushc 6
pushc 6
ge
wrint
pushc 10
wrchr
halt

View File

@@ -0,0 +1,24 @@
pushc 3
pushc 4
gt
wrint
pushc 10
wrchr
pushc 8
pushc 4
gt
wrint
pushc 10
wrchr
pushc 6
pushc 6
gt
wrint
pushc 10
wrchr
halt

19
test/tests/jumpTest.asm Normal file
View File

@@ -0,0 +1,19 @@
pushc 3
pushc 4
wrint
pushc 10
wrchr
pushc 3
jmp L1
pushc 4
L1:
wrint
pushc 10
wrchr
halt

View File

@@ -0,0 +1,24 @@
pushc 3
pushc 4
le
wrint
pushc 10
wrchr
pushc 8
pushc 4
le
wrint
pushc 10
wrchr
pushc 6
pushc 6
le
wrint
pushc 10
wrchr
halt

View File

@@ -0,0 +1,24 @@
pushc 3
pushc 4
lt
wrint
pushc 10
wrchr
pushc 8
pushc 4
lt
wrint
pushc 10
wrchr
pushc 6
pushc 6
lt
wrint
pushc 10
wrchr
halt

BIN
test/tests/nja Executable file

Binary file not shown.

View File

@@ -0,0 +1,15 @@
pushc 3
pushc 4
ne
wrint
pushc 10
wrchr
pushc 6
pushc 6
ne
wrint
pushc 10
wrchr
halt

23
test/tests/objTest.asm Normal file
View File

@@ -0,0 +1,23 @@
pushc 3
newa
popg 0
pushg 0
pushc 0
pushc 9
putfa
pushg 0
pushc 1
pushc 22
putfa
pushg 0
pushc 0
getfa
pushg 0
pushc 1
getfa
add
wrint
halt
// Sollte 21 + 9 ergeben

16
test/tests/prog1.asm Normal file
View File

@@ -0,0 +1,16 @@
pushc 3
pushc 4
eq
brf L1
pushc 4
L1:
pushc 7
wrint
pushc 10
wrchr
halt