Partially implement the Accu

This commit is contained in:
lux 2017-08-09 22:51:27 +02:00
parent 1bdbf7a7e7
commit ad6f5a5854
6 changed files with 47 additions and 14 deletions

View File

@ -1,8 +1,8 @@
#-------------Makro-Part------------------ #-------------Makro-Part------------------
CC = gcc CC = gcc
CFLAGS = -Wall -std=c99 CFLAGS = -Wall -pedantic -std=c99
LDFLAGs = LDFLAGs =
DEBUG = DEBUG = -DNDEBUG
VPATH = src src/debug VPATH = src src/debug
@ -21,5 +21,4 @@ debug.o : debug.c debug.h
$(CC) $(DEBUG) $(CFLAGS) -o $@ -c $< $(CC) $(DEBUG) $(CFLAGS) -o $@ -c $<
clean : clean :
rm -f *.o rm -f *.o coredump*.toy

BIN
src/.main.c.swp Normal file

Binary file not shown.

BIN
src/.toy.h.swp Normal file

Binary file not shown.

View File

@ -1,31 +1,40 @@
#include "toy.h" #include "toy.h"
#include "./debug/debug.h" #include "./debug/debug.h"
#include<assert.h>
#ifndef NDEBUG
#define DEBUG
#endif
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
uint16_t ram[RAM_SIZE]; uint16_t ram[RAM_SIZE];
uint16_t ir; uint16_t ir=0;
uint8_t op_code; uint8_t op_code;
uint16_t pc = 0; uint16_t pc = 0;
uint16_t accu = 0;
int data_addr=0; int data_addr=0;
bool run = true; bool run = true;
if(initialise_ram(ram,argc,argv)==-1) return 1; if(initialise_ram(ram,argc,argv)==-1) return 1;
// makeHexDump(true,ram);
// while(run && pc<(RAM_SIZE-1)) // while(run && pc<(RAM_SIZE-1))
// { // {
ir = ram[2]; ir = ram[pc];
pc++;
op_code = get_opcode(ir); op_code = get_opcode(ir);
printf("OP Code: %u\n",op_code);
data_addr=find_data(ir); data_addr=find_data(ir);
#ifdef DEBUG
printf("OP Code: %u\n",op_code);
printf("Adresse: %d\n",data_addr); printf("Adresse: %d\n",data_addr);
makeHexDump(true,ram);
#endif
if(execute(op_code,data_addr,*ram))
pc=data_addr(ram[pc]);
else pc++;
// } // }
return 0; return 0;
} }

View File

@ -5,7 +5,6 @@ int initialise_ram(uint16_t *ram, int argc, char **argv )
{ {
//open Input Stream //open Input Stream
FILE *fp; FILE *fp;
int j=0; int j=0;
char tempS[CPU_WORD_SIZE+1]; //+1 for "\0" char tempS[CPU_WORD_SIZE+1]; //+1 for "\0"
@ -66,4 +65,29 @@ int find_data(uint16_t instruction)
return instr; return instr;
} }
bool execute(uint8_t op_code, int data_addr, uint16_t *ram) // jump when 1
{
//vorsicht uint16 und Zweierkomplement noch nicht stringent !!!
//Vorsicht bool ops bei sigend int typs sind undefiniert !
static uint16_t accu;
switch(op_code)
{
case 0: ram[data_addr]=accu; break;
case 1: accu=ram[data_addr]; break;
// case 2: if(!accu) break;
case 3: accu=accu + ram[data_addr]; break;
case 4: accu=accu - ram[data_addr]; break;
case 5: accu=accu | ram[data_addr]; break;
case 6: accu=accu & ram[data_addr]; break;
case 7: accu=accu & ram[data_addr]; break;
case 8: break;
case 9: break;
case 10: break;
case 11: break;
case 12: break;
case 13: break;
case 14: break;
case 15: break;
}

View File

@ -13,5 +13,6 @@
int initialise_ram(uint16_t *ram, int argc, char **argv ); int initialise_ram(uint16_t *ram, int argc, char **argv );
uint8_t get_opcode(uint16_t instruction); uint8_t get_opcode(uint16_t instruction);
int find_data(uint16_t instruction); int find_data(uint16_t instruction);
bool execute(uint8_t op_code, int data_addr,uint16_t *ram);
#endif #endif