70 Commits

Author SHA1 Message Date
906ea30be2 update 2024-01-18 18:25:00 +01:00
nils polek
70dbd0253b Big int works 2024-01-18 17:17:07 +00:00
5039f95153 Revert "update"
This reverts commit dbafdbeea5ec44865047cbcce23d20d0855093ea.
2024-01-18 17:24:01 +01:00
dbafdbeea5 update 2024-01-18 16:21:34 +01:00
nils polek
ac57431ac4 added big int lib 2024-01-15 16:28:41 +00:00
nils polek
3935d2778b alle rechenobjekte im stack sind jetzt pointer 2024-01-15 15:32:02 +00:00
nils polek
37843d9356 Added a debug menue 2024-01-15 12:43:49 +00:00
nils polek
6cc2ff87ca Stack uses only references and equation objects 2024-01-15 11:48:21 +00:00
nils polek
f29f500d0c added some shit 2024-01-14 20:09:51 +00:00
nils polek
23e787eb5e added pushr popr 2024-01-14 17:39:11 +00:00
nils polek
94fb404c71 Added nja njc and Makefile 2024-01-14 17:11:09 +00:00
847f68bb29 fix error 2023-12-28 22:29:30 +01:00
da06afd43b update version to 8 2023-12-28 22:28:35 +01:00
9421d34756 add heap and stack args (not yet implemented) 2023-12-28 22:25:40 +01:00
Nils Polek
60bdfd7843 Added DUB 2023-12-10 00:24:17 +01:00
bdb0ce63b8 fix dfbnjkhghjdfsbg 2023-12-10 00:18:20 +01:00
dcb665f5a6 update debug 2023-12-10 00:00:59 +01:00
Nils Polek
82dc5f28cc abc 2023-12-09 23:43:33 +01:00
8be99c5244 update debug 2023-12-09 23:15:11 +01:00
742f050b24 update debug 2023-12-09 23:14:19 +01:00
14025d3b08 update debug 2023-12-09 23:12:33 +01:00
3f12378110 update debug 2023-12-09 23:11:42 +01:00
2cb94eaf76 update debug 2023-12-09 23:10:31 +01:00
9d64b87a09 update debug 2023-12-09 23:10:23 +01:00
b87ebbe841 update debug 2023-12-09 23:03:32 +01:00
829735eb8c update debug 2023-12-09 22:57:26 +01:00
44f70a1777 update debug 2023-12-09 22:51:27 +01:00
5a7338f91c update debug 2023-12-09 22:49:44 +01:00
a8999f4ec2 update debug 2023-12-09 22:43:53 +01:00
c0a5e694c0 update debug
fix call not jumping
2023-12-09 22:42:46 +01:00
Nils Polek
61a138fdee versin v 2023-12-09 22:40:18 +01:00
55af679c39 fix jump not working right 2023-12-09 22:10:02 +01:00
27400289f5 update debug 2023-12-09 22:00:13 +01:00
c0d25212af fix printProgram 2023-12-09 21:56:17 +01:00
10a6883750 update debug mode 2023-12-09 21:55:12 +01:00
Nils Polek
33a2994c29 Commit with mistake 2023-12-09 21:40:42 +01:00
Nils Polek
7390df9ee0 Aufgabe 2 Fertig 2023-12-09 20:35:15 +01:00
Nils Polek
83dae77e31 aufgabe 2 stack overflow 2023-12-09 19:45:15 +01:00
nils polek
fb8497fbee changed path 2023-12-03 19:39:50 +01:00
dc16504cd7 Aufgabe 2 fertig 2023-12-03 19:30:38 +01:00
2a427a2563 Aufgabe 2 fertig 2023-12-03 18:19:39 +01:00
0e52973475 Aufgabe 2 fertig 2023-12-03 18:14:27 +01:00
nils polek
8b3770df80 added codeReader and consts.c 2023-12-03 16:10:33 +01:00
dc33e46e24 update help 2023-12-03 14:59:02 +01:00
c900a0444f fix printing negative numbers 2023-12-03 14:29:07 +01:00
c16fe6349b add error message if no program selected
fix error with negative numbers
2023-12-03 14:24:22 +01:00
1363db7c11 Finished cleaning up the code 2023-10-30 12:51:42 +01:00
dfedf2e717 test 2023-10-30 11:59:56 +01:00
4d547cca6a #include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "instruktion.c"
#include "code.c"
#include "stack.c"

//Comment to disable debug

// #define DEBUG

// Stack
struct stack stack;
#define SIZE 1000

unsigned int* programmSpeicher;

void copyToProgramm(unsigned int codeToCopy[]){
  programmSpeicher = codeToCopy;
}

void version(void) {
    printf("Ninja Virtual Machine version %i (compiled %s, %s)\n", 0, __DATE__, __TIME__);
}

void help(void) {
    printf("usage: ./njvm [option] [option] ...\n\t--version\tshow version and exit\n\t--help\t\tshow this help and exit\n");
}
void printProgramm(){
  int i = 0;
  char c[10];
  while (programmSpeicher[i] != 0)
  {
    switch (programmSpeicher[i] >> 24) {
      case PUSHC:
        strcpy(c,"pushc");
      break;
      case ADD:
        strcpy(c,"add");
      break;
      case SUB:
        strcpy(c,"sub");
      break;
      case MUL:
        strcpy(c,"mul");
      break;
      case DIV:
        strcpy(c,"div");
      break;
      case MOD:
        strcpy(c,"mod");
      break;
      case RDINT:
        strcpy(c,"rdint");
      break;
      case WRINT:
        strcpy(c,"wrint");
      break;
      case RDCHR:
        strcpy(c,"rdchr");
      break;
      case WRCHR:
        strcpy(c,"wrchr");
      break;
      default:
        strcpy(c,"halt");
      break;
    }
    IMMEDIATE(programmSpeicher[i])? printf("%03i:\t%s\t%i\n",i,c,IMMEDIATE(programmSpeicher[i])) : printf("%03i:\t%s\n",i,c);
       i++;
  }
  printf("%03i:\thalt\n",i);
}
void execute(void) {
    int i = 0;
    int intInput;
    int temp;
    char charInput;
    while (1) {

        switch (programmSpeicher[i] >> 24) {
            case HALT:
                  goto end;
                break;
            case PUSHC:
                  push(stack,IMMEDIATE(programmSpeicher[i]));
                break;
            case ADD:
                  push(stack,pop(stack)+pop(stack));
                break;
            case SUB:
                  temp = pop(stack);
                  push(stack,pop(stack) - temp);
                break;
            case MUL:
                  push(stack,pop(stack)*pop(stack));
                break;
            case DIV:
                  temp = pop(stack);
                  push(stack,pop(stack)/temp);
                break;
            case MOD:
                  temp = pop(stack);
                  push(stack,pop(stack)%temp);
                break;
            case RDINT:
                  scanf("%i",&intInput);
                  push(stack,intInput);
                break;
            case WRINT:
                  printf("%i",pop(stack));
                break;
            case RDCHR:
                  scanf("%c",&charInput);
                  push(stack,charInput);
                break;
            case WRCHR:
                  printf("%c",pop(stack));
                break;
        }
        i++;
    }
end:
  return;
}
#ifdef DEBUG

void tests(void){
  printf("Runnig debug mode\n");
  copyToProgramm(code1);
  printProgramm();
  execute();
}

#endif /* ifdef DEBUG */

int main(int argc, char *argv[]) {
  int size = SIZE;
  int current = 0;
  unsigned int s[SIZE];
  stack.size = &size;
  stack.current = &current;
  stack.stack = s;
    #ifdef DEBUG
      tests();
    #endif /* ifdef DEBUG */
     if (argc > 1) {
        if (strcmp(argv[1], "--version") == 0) {
            version();
        } else if (strcmp(argv[1], "--help") == 0) {
            help();
        } else if (strcmp(argv[1], "--prog1") == 0) {
            copyToProgramm(code1);
            goto run;
        } else if (strcmp(argv[1],"--prog2") == 0) {
            copyToProgramm(code2);
            goto run;
        }else if (strcmp(argv[1],"--prog3") == 0) {
            copyToProgramm(code3);
            goto run;
        }else {
            printf("unknown command line argument '%s', try './njvm --help'", argv[1]);
        }
    } else {
  run:
//    Started
        printf("Ninja Virtual Machine started\n");
        printProgramm();
        execute();
//    Stopped
        printf("Ninja Virtual Machine stopped\n");
        return 0;
    }
}
2023-10-30 00:24:55 +01:00
6740f41edc stack organized 2023-10-30 00:17:17 +01:00