Comment code in the main-function
This commit is contained in:
parent
0317a9ebfc
commit
ac48d2c6b7
25
src/main.c
25
src/main.c
@ -11,24 +11,26 @@
|
|||||||
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=0;
|
uint16_t ir=0; //Instruction Register
|
||||||
uint8_t op_code;
|
uint8_t op_code; //CPU Operation Code
|
||||||
uint16_t pc = 0;
|
uint16_t pc = 0; //Program Counter
|
||||||
int data_addr=0;
|
int data_addr=0; //Adress of the 2nd operator (1. is ACCU)
|
||||||
int quit='n';
|
int quit='n'; //Helper for program-flow exit (not part of CPU)
|
||||||
bool run = true;
|
bool run = true; //CPU halt and reset.(make better a coredamp befor)
|
||||||
|
|
||||||
printf("\n+++++++++++++++++++++++++++++++++++++++++++++++\n+Boot: "CPU_TYPE
|
printf("\n+++++++++++++++++++++++++++++++++++++++++++++++\n+Boot: "CPU_TYPE
|
||||||
" wite %zu x %zu Bit RAM.+\n+++++++++++++++++++++++++++++++++++++++++++++++\n\n"
|
" wite %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;
|
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))
|
while(run && pc<(RAM_SIZE-1))
|
||||||
{
|
{
|
||||||
ir = ram[pc];
|
ir = ram[pc]; //get instruction from RAM
|
||||||
op_code = get_opcode(ir);
|
op_code = get_opcode(ir); //determine the instruction form
|
||||||
data_addr=find_data(ir);
|
data_addr=find_data(ir); //locate the 2nd operand (ignord from OP_Code 8 to 15)
|
||||||
|
|
||||||
//Handele user output
|
//Handele user output
|
||||||
printf("\ninstruction: ");
|
printf("\ninstruction: ");
|
||||||
@ -36,8 +38,9 @@ int main(int argc, char *argv[])
|
|||||||
printf("OP Code: %"PRIu8"\t",op_code);
|
printf("OP Code: %"PRIu8"\t",op_code);
|
||||||
printf("Adresse: %u\n",data_addr);
|
printf("Adresse: %u\n",data_addr);
|
||||||
printf("\ninstruction result:\n");
|
printf("\ninstruction result:\n");
|
||||||
|
|
||||||
//CPU control flow
|
//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]);
|
pc=find_data(ram[pc]);
|
||||||
else pc++;
|
else pc++;
|
||||||
|
|
||||||
|
@ -13,7 +13,8 @@ int initialise_ram(uint16_t *ram, int argc, char **argv )
|
|||||||
|
|
||||||
if(argc<2)
|
if(argc<2)
|
||||||
{
|
{
|
||||||
fprintf(stderr,"%s","no \".toy\" input file!\n");
|
fprintf(stderr,"%s","no \".toy\" input file!\n"
|
||||||
|
"interpretation terminated.\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if(argc >2)
|
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
|
bool execute(uint8_t op_code, int data_addr, uint16_t *ram) // jump when 1
|
||||||
{
|
{
|
||||||
|
//Vorsicht: bool ops bei sigend int typs sind nach c99 undefiniert !
|
||||||
//vorsicht uint16 und Zweierkomplement noch nicht stringent !!!
|
|
||||||
//Vorsicht bool ops bei sigend int typs sind undefiniert !
|
|
||||||
static uint16_t accu;
|
static uint16_t accu;
|
||||||
bool jump=false;
|
bool jump=false;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user