Finish rough ACCU implementation!
This commit is contained in:
parent
ad6f5a5854
commit
caf2b81431
BIN
src/.main.c.swp
BIN
src/.main.c.swp
Binary file not shown.
BIN
src/.toy.h.swp
BIN
src/.toy.h.swp
Binary file not shown.
18
src/main.c
18
src/main.c
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
37
src/toy.c
37
src/toy.c
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user