change some data types for loops/array index
fix some spelling and formatting errors
This commit is contained in:
parent
2be60bb718
commit
a717499339
20
src/main.c
20
src/main.c
@ -17,7 +17,7 @@ int main(int argc, char *argv[])
|
|||||||
uint16_t ir=0; //Instruction Register
|
uint16_t ir=0; //Instruction Register
|
||||||
uint8_t op_code; //CPU Operation Code
|
uint8_t op_code; //CPU Operation Code
|
||||||
uint16_t pc = 0; //Program Counter
|
uint16_t pc = 0; //Program Counter
|
||||||
int data_addr=0; //Adress of the 2nd operand (1. is ACCU)
|
uint16_t data_addr=0; //Adress of the 2nd operand (1. is ACCU)
|
||||||
int quit='n'; //Helper for program-flow exit (not part of CPU)
|
int quit='n'; //Helper for program-flow exit (not part of CPU)
|
||||||
bool run = true; //CPU halt and reset.(make better a coredamp befor)
|
bool run = true; //CPU halt and reset.(make better a coredamp befor)
|
||||||
|
|
||||||
@ -25,31 +25,31 @@ int main(int argc, char *argv[])
|
|||||||
" with %zu x %zu Bit RAM.+\n+++++++++++++++++++++++++++++++++++++++++++++++\n\n"
|
" with %zu x %zu Bit RAM.+\n+++++++++++++++++++++++++++++++++++++++++++++++\n\n"
|
||||||
,(sizeof(ram)/sizeof(ram[0])),sizeof(ram[0])*8);
|
,(sizeof(ram)/sizeof(ram[0])),sizeof(ram[0])*8);
|
||||||
|
|
||||||
if(initialise_ram(ram,argc,argv)==-1) return 1; //load data from command line into RAM
|
if(initialise_ram(ram,argc,argv)==-1) return 1; /*load data from command line into RAM
|
||||||
//(-1 in case of error,
|
(-1 in case of error,
|
||||||
//else number of correct read worts)
|
else number of correct read worts)*/
|
||||||
|
|
||||||
while(run)
|
while(run)
|
||||||
{
|
{
|
||||||
ir = ram[pc]; //get instruction from RAM
|
ir = ram[pc]; //get instruction from RAM
|
||||||
op_code = get_opcode(ir); //determine the instruction form
|
op_code = get_opcode(ir); //determine the instruction form
|
||||||
data_addr=get_data(ir); //locate the 2nd operand (ignord from OP_Code 8 to 15)
|
data_addr=get_data(ir); //locate the 2nd operand (ignord from OP_Code 8 to 15)
|
||||||
|
|
||||||
//Handele user output
|
//handle user output
|
||||||
printf("\ninstruction: ");
|
printf("\ninstruction: ");
|
||||||
fprintBits(sizeof(*ram), ram+pc,stdout);
|
fprintBits(sizeof(*ram), ram+pc,stdout);
|
||||||
printf("OP Code: %"PRIu8"\t",op_code);
|
printf("OP Code: %"PRIu8"\t",op_code);
|
||||||
printf("Adresse: %u\n",data_addr);
|
printf("Adresse: %"PRIu16"\n",data_addr);
|
||||||
printf("\ninstruction result:\n");
|
printf("\ninstruction result:\n");
|
||||||
|
|
||||||
//CPU control flow
|
//CPU control flow
|
||||||
if(execute(op_code,data_addr,ram)) //EXECUTE instruction, jump if ALU says
|
if(execute(op_code,data_addr,ram)) //EXECUTE instruction, jump if ALU says
|
||||||
pc=get_data(ir);
|
pc=get_data(ir);
|
||||||
else pc++;
|
else pc++;
|
||||||
|
|
||||||
if(pc>=RAM_SIZE) pc %= RAM_SIZE; //TOY_CPU can only address 12 Bit
|
if(pc>=RAM_SIZE) pc %= RAM_SIZE; //TOY_CPU can only address 12 Bit
|
||||||
|
|
||||||
//Handele user output
|
//handle user output
|
||||||
|
printf("ACCU: %d\n",get2compl(*ACCU));
|
||||||
printf("PROGRAM COUNTER: %" PRIu16 "\n",pc);
|
printf("PROGRAM COUNTER: %" PRIu16 "\n",pc);
|
||||||
printf("\x1b[32m \n(n)ext step or (q)uit or (c)oredump ?\n \x1b[0m");
|
printf("\x1b[32m \n(n)ext step or (q)uit or (c)oredump ?\n \x1b[0m");
|
||||||
|
|
||||||
|
@ -46,10 +46,11 @@ int initialise_ram(uint16_t *ram, int argc, char **argv )
|
|||||||
|
|
||||||
//open and check the input stream
|
//open and check the input stream
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
int j=0,int_cache=0;
|
int int_cache=0;
|
||||||
|
size_t j=0;
|
||||||
char tempS[CPU_WORD_SIZE+1]; //+1 for "\0
|
char tempS[CPU_WORD_SIZE+1]; //+1 for "\0
|
||||||
|
|
||||||
for(int i=0;i<RAM_SIZE;i++) ram[i]=0; //initialize the toy-RAM with NULL
|
for(size_t i=0;i<RAM_SIZE;i++) ram[i]=0; //initialize the toy-RAM with NULL
|
||||||
|
|
||||||
if(argc<2)
|
if(argc<2)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user