diff --git a/src/main.c b/src/main.c index f272daa..2b4babf 100644 --- a/src/main.c +++ b/src/main.c @@ -28,6 +28,9 @@ int main(int argc, char *argv[]) if(initialise_ram(ram,argc,argv)==-1) return 1; /*load data from command line into RAM (-1 in case of error, else number of correctly read words)*/ + + print_architecture(); //print cpu architecture at startup + while(run) { ir = ram[pc]; //get instruction from RAM diff --git a/src/toy.c b/src/toy.c index 56b0c57..f8070b8 100644 --- a/src/toy.c +++ b/src/toy.c @@ -41,6 +41,40 @@ void print_instructionSet(void) "\tmichael.krause@uni-leipzig.de\n"); } +void print_architecture(void) +{ + printf( +" +---------------+ +--------+\n" +" | | v |\n" +" +------------v------------+ | +--+-----+ |\n" +" | INSTRUCTION REGISTER(IR)| | |ACCU | |\n" +" +-------------------------+ | |(16 BIT)| |\n" +" ||OP-CODE || ADDRESS || | +--+-----+ |\n" +" ||(4 BIT) || (12 BIT) || | | |\n" +" |----+-----------+--------| | | |\n" +" +--- | --------- | -------+ +------| | |\n" +" | | | v v |\n" +" +--------+ +--------+ | +-+--+ +--+-+ |\n" +" | | | | | +----+ | |\n" +" v | v | | ALU | |\n" +"+-----+-------+ | +----+--------+ | ++ (16 BIT) +-+ |\n" +"| | | | PC | | ++ ++ |\n" +"|CONTROL LOGIC| | | 12 BIT | | +-------+-+ |\n" +"| | | | | | | |\n" +"+-------------+ | +-+-----------+ | +-----------+\n" +" | | | v\n" +" v v | +------------+----------+\n" +" +-++ ++-+ | | DATA IN |\n" +" | +---+ | +-+ DATA OUT |\n" +" | MUX | | +-------------------+ |\n" +" ++ 12 BIT++ | |4k WORDS OF 16 BITS| |\n" +" +---+---+ | +-------------------+ |\n" +" | | |\n" +" +------------------ > ADDR |\n" +" +-----------------------+\n" +"\n"); +} + void print_instruction(uint8_t opcode) { opcode%=16; @@ -94,6 +128,13 @@ int initialise_ram(uint16_t *ram, int argc, char **argv ) return -1; } + if(strcmp(argv[1],"-i")==0) + { + printf("interpretation terminated.\n\n"); + print_architecture(); + return -1; + } + if(NULL==(fp=fopen(argv[1],"r"))) { fprintf(stderr,"%s","open input stream error !\n"); diff --git a/src/toy.h b/src/toy.h index ae6350e..35c32fd 100644 --- a/src/toy.h +++ b/src/toy.h @@ -17,6 +17,16 @@ extern const uint16_t * const ACCU; //read only access to accu void print_instructionSet(void); +/** +* print_instructionSet(): prints the cpu architecture. +* This is a user help function and can be activated via +* the -i parameter. +* Return: none +*/ + + +void print_architecture(void); + /** * print_instruction(): converts a OP-Code into a human word. * Return: none