Set istruzioni completato, si spera + tutti gli stub
This commit is contained in:
		
							parent
							
								
									d8bd273df9
								
							
						
					
					
						commit
						702bb1ad9b
					
				@ -10,7 +10,8 @@ enum OPS_STARTING_VALUES {
 | 
			
		||||
  ADDR,
 | 
			
		||||
  SUBI,
 | 
			
		||||
  SUBR,
 | 
			
		||||
  XORI,
 | 
			
		||||
  XORB,
 | 
			
		||||
  XORW,
 | 
			
		||||
  XORR,
 | 
			
		||||
  NOTR,
 | 
			
		||||
  MULI,
 | 
			
		||||
@ -19,27 +20,57 @@ enum OPS_STARTING_VALUES {
 | 
			
		||||
  DIVR,
 | 
			
		||||
  PUSH,
 | 
			
		||||
  POOP,
 | 
			
		||||
  COMP,
 | 
			
		||||
  CMPI,
 | 
			
		||||
  CMPR,
 | 
			
		||||
  JUMP,
 | 
			
		||||
  JMPA,
 | 
			
		||||
  JMPB,
 | 
			
		||||
  JMPE,
 | 
			
		||||
  SHIT,
 | 
			
		||||
  NOPE,
 | 
			
		||||
  GERM,
 | 
			
		||||
  GRMN,
 | 
			
		||||
  NUM_OPS
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
uint8_t OPS[NUM_OPS];
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
INSTRUCTION SIZE TYPES
 | 
			
		||||
*/
 | 
			
		||||
#define REG2REG 2
 | 
			
		||||
#define IMM2REG 4
 | 
			
		||||
#define REG2IMM 4
 | 
			
		||||
#define UNARY 1
 | 
			
		||||
#define BYT2REG 3
 | 
			
		||||
#define UNARY 2
 | 
			
		||||
#define SINGLE 1
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
INSTRUCTION SIZES
 | 
			
		||||
*/
 | 
			
		||||
#define MOVI_SIZE IMM2REG
 | 
			
		||||
#define MOVR_SIZE REG2REG
 | 
			
		||||
#define LOAD_SIZE IMM2REG
 | 
			
		||||
#define STOR_SIZE REG2IMM
 | 
			
		||||
#define ADDI_SIZE IMM2REG
 | 
			
		||||
#define ADDR_SIZE REG2REG
 | 
			
		||||
#define ADDR_SIZE REG2REG
 | 
			
		||||
#define SUBI_SIZE IMM2REG
 | 
			
		||||
#define SUBR_SIZE REG2REG
 | 
			
		||||
#define XORB_SIZE BYT2REG
 | 
			
		||||
#define XORW_SIZE IMM2REG
 | 
			
		||||
#define XORR_SIZE REG2REG
 | 
			
		||||
#define NOTR_SIZE UNARY
 | 
			
		||||
#define MULI_SIZE IMM2REG
 | 
			
		||||
#define MULR_SIZE REG2REG
 | 
			
		||||
#define DIVI_SIZE IMM2REG
 | 
			
		||||
#define DIVR_SIZE REG2REG
 | 
			
		||||
#define PUSH_SIZE UNARY
 | 
			
		||||
#define POOP_SIZE UNARY
 | 
			
		||||
#define CMPI_SIZE IMM2REG
 | 
			
		||||
#define CMPR_SIZE REG2REG
 | 
			
		||||
#define JUMP_SIZE UNARY
 | 
			
		||||
#define JMPA_SIZE UNARY
 | 
			
		||||
#define JMPB_SIZE UNARY
 | 
			
		||||
#define JMPE_SIZE UNARY
 | 
			
		||||
#define SHIT_SIZE SINGLE
 | 
			
		||||
#define NOPE_SIZE SINGLE
 | 
			
		||||
#define GRMN_SIZE SINGLE
 | 
			
		||||
							
								
								
									
										67
									
								
								cpp/vm.cpp
									
									
									
									
									
								
							
							
						
						
									
										67
									
								
								cpp/vm.cpp
									
									
									
									
									
								
							@ -254,7 +254,8 @@ bool VM::execADDR(void) {
 | 
			
		||||
 | 
			
		||||
bool VM::execSUBI(void) { return true; }
 | 
			
		||||
bool VM::execSUBR(void) { return true; }
 | 
			
		||||
bool VM::execXORI(void) { return true; }
 | 
			
		||||
bool VM::execXORB(void) { return true; }
 | 
			
		||||
bool VM::execXORW(void) { return true; }
 | 
			
		||||
bool VM::execXORR(void) { return true; }
 | 
			
		||||
bool VM::execNOTR(void) { return true; }
 | 
			
		||||
bool VM::execMULI(void) { return true; }
 | 
			
		||||
@ -263,12 +264,13 @@ bool VM::execDIVI(void) { return true; }
 | 
			
		||||
bool VM::execDIVR(void) { return true; }
 | 
			
		||||
bool VM::execPUSH(void) { return true; }
 | 
			
		||||
bool VM::execPOOP(void) { return true; }
 | 
			
		||||
bool VM::execCOMP(void) { return true; }
 | 
			
		||||
bool VM::execCMPI(void) { return true; }
 | 
			
		||||
bool VM::execCMPR(void) { return true; }
 | 
			
		||||
bool VM::execJUMP(void) { return true; }
 | 
			
		||||
bool VM::execJMPA(void) { return true; }
 | 
			
		||||
bool VM::execJMPB(void) { return true; }
 | 
			
		||||
bool VM::execJMPE(void) { return true; }
 | 
			
		||||
bool VM::execGERM(void) { return true; }
 | 
			
		||||
bool VM::execGRMN(void) { return true; }
 | 
			
		||||
void VM::run(void) {
 | 
			
		||||
  uint8_t opcode;
 | 
			
		||||
  bool finished = false;
 | 
			
		||||
@ -289,8 +291,67 @@ void VM::run(void) {
 | 
			
		||||
    } else if (opcode == OPS[ADDI]) {
 | 
			
		||||
      execADDI();
 | 
			
		||||
      regs[IP] += ADDI_SIZE;
 | 
			
		||||
    } else if (opcode == OPS[ADDR]) {
 | 
			
		||||
      execADDR();
 | 
			
		||||
      regs[IP] += ADDR_SIZE;
 | 
			
		||||
    } else if (opcode == OPS[SUBI]) {
 | 
			
		||||
      execSUBI();
 | 
			
		||||
      regs[IP] += SUBI_SIZE;
 | 
			
		||||
    } else if (opcode == OPS[SUBR]) {
 | 
			
		||||
      execSUBR();
 | 
			
		||||
      regs[IP] += SUBR_SIZE;
 | 
			
		||||
    } else if (opcode == OPS[XORB]) {
 | 
			
		||||
      execXORB();
 | 
			
		||||
      regs[IP] += XORB_SIZE;
 | 
			
		||||
    } else if (opcode == OPS[XORW]) {
 | 
			
		||||
      execXORW();
 | 
			
		||||
      regs[IP] += XORW_SIZE;
 | 
			
		||||
    } else if (opcode == OPS[XORR]) {
 | 
			
		||||
      execXORR();
 | 
			
		||||
      regs[IP] += XORR_SIZE;
 | 
			
		||||
    } else if (opcode == OPS[NOTR]) {
 | 
			
		||||
      execNOTR();
 | 
			
		||||
      regs[IP] += NOTR_SIZE;
 | 
			
		||||
    } else if (opcode == OPS[MULI]) {
 | 
			
		||||
      execMULI();
 | 
			
		||||
      regs[IP] += MULI_SIZE;
 | 
			
		||||
    } else if (opcode == OPS[MULR]) {
 | 
			
		||||
      execMULR();
 | 
			
		||||
      regs[IP] += MULR_SIZE;
 | 
			
		||||
    } else if (opcode == OPS[DIVI]) {
 | 
			
		||||
      execDIVI();
 | 
			
		||||
      regs[IP] += DIVI_SIZE;
 | 
			
		||||
    } else if (opcode == OPS[PUSH]) {
 | 
			
		||||
      execPUSH();
 | 
			
		||||
      regs[IP] += PUSH_SIZE;
 | 
			
		||||
    } else if (opcode == OPS[POOP]) {
 | 
			
		||||
      execPOOP();
 | 
			
		||||
      regs[IP] += POOP_SIZE;
 | 
			
		||||
    } else if (opcode == OPS[CMPI]) {
 | 
			
		||||
      execCMPI();
 | 
			
		||||
      regs[IP] += CMPI_SIZE;
 | 
			
		||||
    } else if (opcode == OPS[CMPR]) {
 | 
			
		||||
      execCMPR();
 | 
			
		||||
      regs[IP] += CMPR_SIZE;
 | 
			
		||||
    } else if (opcode == OPS[JUMP]) {
 | 
			
		||||
      execJUMP();
 | 
			
		||||
      regs[IP] += JUMP_SIZE;
 | 
			
		||||
    } else if (opcode == OPS[JMPA]) {
 | 
			
		||||
      execJMPA();
 | 
			
		||||
      regs[IP] += JMPA_SIZE;
 | 
			
		||||
    } else if (opcode == OPS[JMPB]) {
 | 
			
		||||
      execJMPB();
 | 
			
		||||
      regs[IP] += JMPB_SIZE;
 | 
			
		||||
    } else if (opcode == OPS[JMPE]) {
 | 
			
		||||
      execJMPE();
 | 
			
		||||
      regs[IP] += JMPE_SIZE;
 | 
			
		||||
    } else if (opcode == OPS[GRMN]) {
 | 
			
		||||
      execGRMN();
 | 
			
		||||
      regs[IP] += GRMN_SIZE;
 | 
			
		||||
    } else if (opcode == OPS[SHIT]) {
 | 
			
		||||
      finished = true;
 | 
			
		||||
    } else if (opcode == OPS[NOPE]) {
 | 
			
		||||
      regs[IP] += NOPE_SIZE;
 | 
			
		||||
    } else {
 | 
			
		||||
      DBG_ERROR(("WAT\n"));
 | 
			
		||||
      finished = true;
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										8
									
								
								cpp/vm.h
									
									
									
									
									
								
							
							
						
						
									
										8
									
								
								cpp/vm.h
									
									
									
									
									
								
							@ -39,7 +39,8 @@ private:
 | 
			
		||||
  bool execADDR(void);
 | 
			
		||||
  bool execSUBI(void);
 | 
			
		||||
  bool execSUBR(void);
 | 
			
		||||
  bool execXORI(void);
 | 
			
		||||
  bool execXORB(void);
 | 
			
		||||
  bool execXORW(void);
 | 
			
		||||
  bool execXORR(void);
 | 
			
		||||
  bool execNOTR(void);
 | 
			
		||||
  bool execMULI(void);
 | 
			
		||||
@ -48,12 +49,13 @@ private:
 | 
			
		||||
  bool execDIVR(void);
 | 
			
		||||
  bool execPUSH(void);
 | 
			
		||||
  bool execPOOP(void);
 | 
			
		||||
  bool execCOMP(void);
 | 
			
		||||
  bool execCMPI(void);
 | 
			
		||||
  bool execCMPR(void);
 | 
			
		||||
  bool execJUMP(void);
 | 
			
		||||
  bool execJMPA(void);
 | 
			
		||||
  bool execJMPB(void);
 | 
			
		||||
  bool execJMPE(void);
 | 
			
		||||
  bool execGERM(void);
 | 
			
		||||
  bool execGRMN(void);
 | 
			
		||||
 | 
			
		||||
public:
 | 
			
		||||
  VM(uint8_t *key);
 | 
			
		||||
 | 
			
		||||
@ -259,14 +259,15 @@ op_names = ["MOVI",
 | 
			
		||||
            "DIVR",
 | 
			
		||||
            "PUSH",
 | 
			
		||||
            "POOP",
 | 
			
		||||
            "COMP",
 | 
			
		||||
            "CMPI",
 | 
			
		||||
            "CMPR",
 | 
			
		||||
            "JUMP",
 | 
			
		||||
            "JMPA",
 | 
			
		||||
            "JMPB",
 | 
			
		||||
            "JMPE",
 | 
			
		||||
            "SHIT",
 | 
			
		||||
            "NOPE",
 | 
			
		||||
            "GERM"]
 | 
			
		||||
            "GRMN"]
 | 
			
		||||
 | 
			
		||||
reg_names = ["R0", "R1", "R2", "R3", "S0", "S1", "S2", "S3", "IP", "BP", "SP"]
 | 
			
		||||
section_names = ["DATA:", "CODE:", "STACK:"]
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user