added some sht
This commit is contained in:
parent
f0d74a7e17
commit
e8b4062331
14
njvm.c
14
njvm.c
@ -8,6 +8,7 @@
|
||||
#include "SDA.c"
|
||||
#include "debugMenu.c"
|
||||
#include "bigint.h"
|
||||
#include "record.c"
|
||||
|
||||
// Debug
|
||||
int debug = 0;
|
||||
@ -240,6 +241,19 @@ void execute(struct program program) {
|
||||
if (debug == 1) printf("pushr");
|
||||
push(stack, pop(reg));
|
||||
break;
|
||||
case NEW:
|
||||
if (debug == 1) printf("new");
|
||||
push(stack, newRecord(SIGN_EXTEND(IMMEDIATE(program.program[i]))))
|
||||
break;
|
||||
case GETF:
|
||||
if (debug == 1) printf("getf");
|
||||
push(stack, getField(pop(stack), SIGN_EXTEND(IMMEDIATE(program.program[i]))))
|
||||
break;
|
||||
case PUTF:
|
||||
if (debug == 1) printf("putf");
|
||||
tempObj = pop(stack)
|
||||
setField(pop(stack), SIGN_EXTEND(IMMEDIATE(program.program[i])),tempObj)
|
||||
break;
|
||||
}
|
||||
}
|
||||
end:
|
||||
|
||||
25
record.c
Normal file
25
record.c
Normal file
@ -0,0 +1,25 @@
|
||||
//
|
||||
// Created by Nils Polek on 23.01.24.
|
||||
//
|
||||
#ifndef RECORD
|
||||
#define RECORD
|
||||
#include "stackslot.c"
|
||||
#include "instruktion.c"
|
||||
ObjRef newRecord(int size){
|
||||
ObjRef record;
|
||||
if((record = malloc(*record + size * sizeof(void *)))== NULL){
|
||||
perror("malloc")
|
||||
}
|
||||
record->size = MSB & size;
|
||||
for(int i = 0; i < size; i++) {
|
||||
GET_REFS_PTR(record)[i] = malloc(8)
|
||||
}
|
||||
}
|
||||
ObjRef getField(ObjRef array, int point){
|
||||
return *(ObjRef *)GET_REFS_PTR(array)[point]->data
|
||||
}
|
||||
setField(ObjRef array, int point, ObjRef value){
|
||||
(ObjRef *)GET_REFS_PTR(array)[point]->data = value
|
||||
}
|
||||
|
||||
#endif
|
||||
155
test.asm
Normal file
155
test.asm
Normal file
@ -0,0 +1,155 @@
|
||||
//
|
||||
// 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 2
|
||||
new 2
|
||||
popl 1
|
||||
pushl 1
|
||||
pushc 5
|
||||
putf 0
|
||||
pushl 1
|
||||
getf 0
|
||||
popl 0
|
||||
pushl 1
|
||||
pushc 2
|
||||
pushl 0
|
||||
mul
|
||||
putf 1
|
||||
pushl 1
|
||||
getf 0
|
||||
call _writeInteger
|
||||
drop 1
|
||||
pushc 1
|
||||
newa
|
||||
dup
|
||||
pushc 0
|
||||
pushc 10
|
||||
putfa
|
||||
call _writeString
|
||||
drop 1
|
||||
pushl 1
|
||||
getf 1
|
||||
call _writeInteger
|
||||
drop 1
|
||||
pushc 1
|
||||
newa
|
||||
dup
|
||||
pushc 0
|
||||
pushc 10
|
||||
putfa
|
||||
call _writeString
|
||||
drop 1
|
||||
__0:
|
||||
rsf
|
||||
ret
|
||||
Loading…
x
Reference in New Issue
Block a user