Comment code in the main-function

This commit is contained in:
lux 2017-08-17 15:28:30 +02:00
parent 0317a9ebfc
commit ac48d2c6b7
2 changed files with 17 additions and 15 deletions

View File

@ -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++;

View File

@ -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;