From ac48d2c6b737417d2765a4b13a9d036bad4f46bd Mon Sep 17 00:00:00 2001 From: lux Date: Thu, 17 Aug 2017 15:28:30 +0200 Subject: [PATCH] Comment code in the main-function --- src/main.c | 25 ++++++++++++++----------- src/toy.c | 7 +++---- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/src/main.c b/src/main.c index abd65f1..c65f215 100644 --- a/src/main.c +++ b/src/main.c @@ -11,24 +11,26 @@ int main(int argc, char *argv[]) { uint16_t ram[RAM_SIZE]; - uint16_t ir=0; - uint8_t op_code; - uint16_t pc = 0; - int data_addr=0; - int quit='n'; - bool run = true; + 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 operator (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) printf("\n+++++++++++++++++++++++++++++++++++++++++++++++\n+Boot: "CPU_TYPE " wite %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; + 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 && pc<(RAM_SIZE-1)) { - ir = ram[pc]; - op_code = get_opcode(ir); - data_addr=find_data(ir); + ir = ram[pc]; //get instruction from RAM + op_code = get_opcode(ir); //determine the instruction form + data_addr=find_data(ir); //locate the 2nd operand (ignord from OP_Code 8 to 15) //Handele user output printf("\ninstruction: "); @@ -36,8 +38,9 @@ int main(int argc, char *argv[]) printf("OP Code: %"PRIu8"\t",op_code); printf("Adresse: %u\n",data_addr); printf("\ninstruction result:\n"); + //CPU control flow - if(execute(op_code,data_addr,ram)) //jump if ALU says + if(execute(op_code,data_addr,ram)) //EXECUTE instruction, jump if ALU says pc=find_data(ram[pc]); else pc++; diff --git a/src/toy.c b/src/toy.c index 1ae9bcb..d1b91a6 100644 --- a/src/toy.c +++ b/src/toy.c @@ -13,7 +13,8 @@ int initialise_ram(uint16_t *ram, int argc, char **argv ) if(argc<2) { - fprintf(stderr,"%s","no \".toy\" input file!\n"); + fprintf(stderr,"%s","no \".toy\" input file!\n" + "interpretation terminated.\n"); return -1; } if(argc >2) @@ -79,9 +80,7 @@ int get2compl(uint16_t value) 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 ! + //Vorsicht: bool ops bei sigend int typs sind nach c99 undefiniert ! static uint16_t accu; bool jump=false;