From a717499339d4d74728d5ffeb8fd2ddfc36ddaa31 Mon Sep 17 00:00:00 2001 From: lux Date: Sun, 1 Oct 2017 21:11:40 +0200 Subject: [PATCH] change some data types for loops/array index fix some spelling and formatting errors --- src/main.c | 20 ++++++++++---------- src/toy.c | 5 +++-- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/main.c b/src/main.c index 759ed0d..a3ba141 100644 --- a/src/main.c +++ b/src/main.c @@ -17,7 +17,7 @@ int main(int argc, char *argv[]) uint16_t ir=0; //Instruction Register uint8_t op_code; //CPU Operation Code 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) 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" ,(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 - //(-1 in case of error, - //else number of correct read worts) - + if(initialise_ram(ram,argc,argv)==-1) return 1; /*load data from command line into RAM + (-1 in case of error, + else number of correct read worts)*/ while(run) { ir = ram[pc]; //get instruction from RAM 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) - //Handele user output + //handle user output printf("\ninstruction: "); fprintBits(sizeof(*ram), ram+pc,stdout); printf("OP Code: %"PRIu8"\t",op_code); - printf("Adresse: %u\n",data_addr); + printf("Adresse: %"PRIu16"\n",data_addr); printf("\ninstruction result:\n"); //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); 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("\x1b[32m \n(n)ext step or (q)uit or (c)oredump ?\n \x1b[0m"); diff --git a/src/toy.c b/src/toy.c index 04e21a7..b85257d 100644 --- a/src/toy.c +++ b/src/toy.c @@ -46,10 +46,11 @@ int initialise_ram(uint16_t *ram, int argc, char **argv ) //open and check the input stream 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 - for(int i=0;i