Add a print routine for the CPU architecture.
This commit is contained in:
parent
6ef4c5aa76
commit
8b4e03b96e
@ -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
|
if(initialise_ram(ram,argc,argv)==-1) return 1; /*load data from command line into RAM
|
||||||
(-1 in case of error,
|
(-1 in case of error,
|
||||||
else number of correctly read words)*/
|
else number of correctly read words)*/
|
||||||
|
|
||||||
|
print_architecture(); //print cpu architecture at startup
|
||||||
|
|
||||||
while(run)
|
while(run)
|
||||||
{
|
{
|
||||||
ir = ram[pc]; //get instruction from RAM
|
ir = ram[pc]; //get instruction from RAM
|
||||||
|
41
src/toy.c
41
src/toy.c
@ -41,6 +41,40 @@ void print_instructionSet(void)
|
|||||||
"\tmichael.krause@uni-leipzig.de\n");
|
"\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)
|
void print_instruction(uint8_t opcode)
|
||||||
{
|
{
|
||||||
opcode%=16;
|
opcode%=16;
|
||||||
@ -94,6 +128,13 @@ int initialise_ram(uint16_t *ram, int argc, char **argv )
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(strcmp(argv[1],"-i")==0)
|
||||||
|
{
|
||||||
|
printf("interpretation terminated.\n\n");
|
||||||
|
print_architecture();
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
if(NULL==(fp=fopen(argv[1],"r")))
|
if(NULL==(fp=fopen(argv[1],"r")))
|
||||||
{
|
{
|
||||||
fprintf(stderr,"%s","open input stream error !\n");
|
fprintf(stderr,"%s","open input stream error !\n");
|
||||||
|
10
src/toy.h
10
src/toy.h
@ -17,6 +17,16 @@ extern const uint16_t * const ACCU; //read only access to accu
|
|||||||
|
|
||||||
void print_instructionSet(void);
|
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.
|
* print_instruction(): converts a OP-Code into a human word.
|
||||||
* Return: none
|
* Return: none
|
||||||
|
Loading…
Reference in New Issue
Block a user