Finish rough ACCU implementation!

This commit is contained in:
lux 2017-08-10 23:08:50 +02:00
parent ad6f5a5854
commit caf2b81431
5 changed files with 33 additions and 24 deletions

Binary file not shown.

Binary file not shown.

View File

@ -15,24 +15,28 @@ int main(int argc, char *argv[])
uint8_t op_code; uint8_t op_code;
uint16_t pc = 0; uint16_t pc = 0;
int data_addr=0; int data_addr=0;
char quit;
bool run = true; bool run = true;
if(initialise_ram(ram,argc,argv)==-1) return 1; if(initialise_ram(ram,argc,argv)==-1) return 1;
// while(run && pc<(RAM_SIZE-1)) while(run && pc<(RAM_SIZE-1))
// { {
ir = ram[pc]; ir = ram[pc];
op_code = get_opcode(ir); op_code = get_opcode(ir);
data_addr=find_data(ir); data_addr=find_data(ir);
#ifdef DEBUG #ifdef DEBUG
printf("OP Code: %u\n",op_code); printf("OP Code: %"PRIu8"\n",op_code);
printf("Adresse: %d\n",data_addr); printf("Adresse: %d\n",data_addr);
makeHexDump(true,ram);
#endif #endif
if(execute(op_code,data_addr,*ram)) if(execute(op_code,data_addr,ram))
pc=data_addr(ram[pc]); pc=find_data(ram[pc]); //jump if ACCU is ZERO
else pc++; else pc++;
// } printf("(n)ext step or (q)uit or (c)oredump ?\n");
scanf("%c",&quit);
if(quit == 'c') makeHexDump(true,ram);
else if(quit == 'q') run = false;
}

View File

@ -71,23 +71,28 @@ bool execute(uint8_t op_code, int data_addr, uint16_t *ram) // jump when 1
//vorsicht uint16 und Zweierkomplement noch nicht stringent !!! //vorsicht uint16 und Zweierkomplement noch nicht stringent !!!
//Vorsicht bool ops bei sigend int typs sind undefiniert ! //Vorsicht bool ops bei sigend int typs sind undefiniert !
static uint16_t accu; static uint16_t accu;
bool jump=false;
switch(op_code) switch(op_code)
{ {
case 0: ram[data_addr]=accu; break; case 0: ram[data_addr] = accu; break; //STORE
case 1: accu=ram[data_addr]; break; case 1: accu = ram[data_addr]; break; //LOAD
// case 2: if(!accu) break; case 2: jump = ((accu==0) ? true : false); break; //JMPZ
case 3: accu=accu + ram[data_addr]; break; case 3: accu = accu + ram[data_addr]; break; //ADD
case 4: accu=accu - ram[data_addr]; break; case 4: accu = accu - ram[data_addr]; break; //SUB
case 5: accu=accu | ram[data_addr]; break; case 5: accu = accu | ram[data_addr]; break; //OR
case 6: accu=accu & ram[data_addr]; break; case 6: accu = accu & ram[data_addr]; break; //AND
case 7: accu=accu & ram[data_addr]; break; case 7: accu = accu ^ ram[data_addr]; break; //XOR
case 8: break; case 8: accu = ~accu; break; //NOT
case 9: break; case 9: accu++; break; //INC
case 10: break; case 10: accu--; break; //DEC
case 11: break; case 11: accu = 0; break; //ZERO
case 12: break; case 12: ; break; //NOP
case 13: break; case 13: ; break; //NOP
case 14: break; case 14: ; break; //NOP
case 15: break; case 15: ; break; //NOP
}
printf("ACCU: %"PRIu16 "\n",accu);
return jump;
} }

View File

@ -2,7 +2,7 @@
#define TOY_H #define TOY_H
#include <stdio.h> #include <stdio.h>
#include <stdint.h> #include <inttypes.h>
#include <stdbool.h> #include <stdbool.h>
#include <stdlib.h> #include <stdlib.h>