rework spelling
This commit is contained in:
parent
21b0c13056
commit
845adb0f58
16
src/helper.h
16
src/helper.h
@ -2,18 +2,18 @@
|
|||||||
#define DEBUG_H
|
#define DEBUG_H
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* get2compl(): interprets the transfer value as tow's complement
|
* get2compl(): interprets the transfer value as two's complement
|
||||||
* Return: tow's complement value between -32768 and 32767
|
* Return: two's complement value between -32768 and 32767
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int32_t get2compl(uint16_t value);
|
int32_t get2compl(uint16_t value);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* fprintBits(): interprets an integer value as a binary pattern.(little endian)
|
* fprintBits(): interprets an integer value as a binary pattern.(Little-Endian)
|
||||||
* if you pass the datatype and the address of an integer,
|
* if you transfer the datatype and the address of an integer,
|
||||||
* the funktion will supply the binary representation.
|
* the function will supply the binary representation.
|
||||||
* (give "stdout" as the last parameter for standard output,
|
* (enter "stdout" as the last parameter for standard output,
|
||||||
* otherwise hand over a filepointer)
|
* otherwise enter a file pointer)
|
||||||
* Return: none
|
* Return: none
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -21,7 +21,7 @@ void fprintBits(size_t const size, void const * const ptr, FILE *file_pointer);
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* makeHexDump(): writes the RAM content to a text file.
|
* makeHexDump(): writes the RAM content to a text file.
|
||||||
* if you pass true to base_2, binary code is written to the textfile,
|
* if you enter true for base_2, binary code is written to the text file,
|
||||||
* otherwise hex code.
|
* otherwise hex code.
|
||||||
* Return: none
|
* Return: none
|
||||||
*/
|
*/
|
||||||
|
12
src/main.c
12
src/main.c
@ -17,9 +17,9 @@ int main(int argc, char *argv[])
|
|||||||
uint16_t ir=0; //Instruction Register
|
uint16_t ir=0; //Instruction Register
|
||||||
uint8_t op_code; //CPU Operation Code
|
uint8_t op_code; //CPU Operation Code
|
||||||
uint16_t pc = 0; //Program Counter
|
uint16_t pc = 0; //Program Counter
|
||||||
uint16_t data_addr=0; //Adress of the 2nd operand (1. is ACCU)
|
uint16_t data_addr=0; //Address of the 2nd operand (1. is ACCU)
|
||||||
int quit='n'; //Helper for program-flow exit (not part of CPU)
|
int quit='n'; //Helper for program-flow exit (not part of CPU)
|
||||||
bool run = true; //CPU halt and reset.(make better a coredamp befor)
|
bool run = true; //CPU halt and reset.(Nb: make a coredump beforehand)
|
||||||
|
|
||||||
printf("\n+++++++++++++++++++++++++++++++++++++++++++++++\n+Boot: "CPU_TYPE
|
printf("\n+++++++++++++++++++++++++++++++++++++++++++++++\n+Boot: "CPU_TYPE
|
||||||
" with %zu x %zu Bit RAM.+\n+++++++++++++++++++++++++++++++++++++++++++++++\n\n"
|
" with %zu x %zu Bit RAM.+\n+++++++++++++++++++++++++++++++++++++++++++++++\n\n"
|
||||||
@ -27,13 +27,13 @@ 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 correct read worts)*/
|
else number of correctly read words)*/
|
||||||
while(run)
|
while(run)
|
||||||
{
|
{
|
||||||
ir = ram[pc]; //get instruction from RAM
|
ir = ram[pc]; //get instruction from RAM
|
||||||
op_code = get_opcode(ir); //determine the instruction form
|
op_code = get_opcode(ir); //determine the instruction form
|
||||||
data_addr=get_data(ir); /*locate the 2nd operand
|
data_addr=get_data(ir); /*locate the 2nd operand
|
||||||
(ignord from OP_Code 8 to 15)*/
|
(undefined for OP_Codes 8 to 15)*/
|
||||||
//handle user output
|
//handle user output
|
||||||
printf("\ninstruction:\t");
|
printf("\ninstruction:\t");
|
||||||
fprintBits(sizeof(*ram), ram+pc,stdout);
|
fprintBits(sizeof(*ram), ram+pc,stdout);
|
||||||
@ -45,11 +45,11 @@ int main(int argc, char *argv[])
|
|||||||
printf("\ninstruction result:\n");
|
printf("\ninstruction result:\n");
|
||||||
|
|
||||||
//CPU control flow
|
//CPU control flow
|
||||||
if(execute(op_code,data_addr,ram)) //EXECUTE instruction, jump if ALU says
|
if(execute(op_code,data_addr,ram)) //EXECUTE instruction,jump on ALU
|
||||||
pc=get_data(ir);
|
pc=get_data(ir);
|
||||||
else pc++;
|
else pc++;
|
||||||
|
|
||||||
if(pc>=RAM_SIZE) pc %= RAM_SIZE; //TOY_CPU can only address 12 Bit
|
if(pc>=RAM_SIZE) pc %= RAM_SIZE; //TOY_CPU can only address 12 bits
|
||||||
|
|
||||||
//handle user output
|
//handle user output
|
||||||
printf("ACCU: %d\n",get2compl(*ACCU));
|
printf("ACCU: %d\n",get2compl(*ACCU));
|
||||||
|
14
src/toy.c
14
src/toy.c
@ -32,10 +32,10 @@ void print_instructionSet(void)
|
|||||||
"\t| OP-CODE |\t\tADDRESS\t |\n"
|
"\t| OP-CODE |\t\tADDRESS\t |\n"
|
||||||
"\t---------------------------------------\n\n");
|
"\t---------------------------------------\n\n");
|
||||||
printf("This machine has the following registers:\n"
|
printf("This machine has the following registers:\n"
|
||||||
"16 BIT Instruction Register(4 BIT OP, 12 BIT Adr)\n"
|
"16 BIT Instruction Register(4 BIT OP, 12 BIT Addr)\n"
|
||||||
"16 BIT Accumulator\n"
|
"16 BIT Accumulator\n"
|
||||||
"12 BIT Program Counter\n\n");
|
"12 BIT Program Counter\n\n");
|
||||||
printf("Example: 0001000000001010 on RAM position 0\n"
|
printf("Example: 0001000000001010 at RAM position 0\n"
|
||||||
"0001 means: LOAD the content of ADDRESS 000000001010 into the ACCU\n\n");
|
"0001 means: LOAD the content of ADDRESS 000000001010 into the ACCU\n\n");
|
||||||
printf("This is an interpreter for the Koopman_TOY_CPU by\n"
|
printf("This is an interpreter for the Koopman_TOY_CPU by\n"
|
||||||
"\tmichael.krause@uni-leipzig.de\n");
|
"\tmichael.krause@uni-leipzig.de\n");
|
||||||
@ -68,13 +68,13 @@ void print_instruction(uint8_t opcode)
|
|||||||
int initialise_ram(uint16_t *ram, int argc, char **argv )
|
int initialise_ram(uint16_t *ram, int argc, char **argv )
|
||||||
{
|
{
|
||||||
|
|
||||||
//open and check the input stream
|
//opens and checks the input stream
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
int int_cache=0;
|
int int_cache=0;
|
||||||
size_t j=0;
|
size_t j=0;
|
||||||
char tempS[CPU_WORD_SIZE+1]; //+1 for "\0
|
char tempS[CPU_WORD_SIZE+1]; //+1 for "\0
|
||||||
|
|
||||||
for(size_t i=0;i<RAM_SIZE;i++) ram[i]=0; //initialize the toy-RAM with NULL
|
for(size_t i=0;i<RAM_SIZE;i++) ram[i]=0; //initialise the toy-RAM with NULL
|
||||||
|
|
||||||
if(argc<2)
|
if(argc<2)
|
||||||
{
|
{
|
||||||
@ -96,7 +96,7 @@ int initialise_ram(uint16_t *ram, int argc, char **argv )
|
|||||||
|
|
||||||
if(NULL==(fp=fopen(argv[1],"r")))
|
if(NULL==(fp=fopen(argv[1],"r")))
|
||||||
{
|
{
|
||||||
fprintf(stderr,"%s","open input stream fault !\n");
|
fprintf(stderr,"%s","open input stream error !\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -109,7 +109,7 @@ int initialise_ram(uint16_t *ram, int argc, char **argv )
|
|||||||
|
|
||||||
if((int_cache =='\n' && i<CPU_WORD_SIZE) || (feof(fp) && i!=0))
|
if((int_cache =='\n' && i<CPU_WORD_SIZE) || (feof(fp) && i!=0))
|
||||||
{
|
{
|
||||||
fprintf(stderr,"%s","input file has incorrect machine-word size !\n");
|
fprintf(stderr,"%s","input file has word length error(s) !\n");
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -125,7 +125,7 @@ int initialise_ram(uint16_t *ram, int argc, char **argv )
|
|||||||
tempS[i] = int_cache;
|
tempS[i] = int_cache;
|
||||||
}
|
}
|
||||||
if(feof(fp)) break;
|
if(feof(fp)) break;
|
||||||
tempS[CPU_WORD_SIZE] = '\0'; //replace \n by \0
|
tempS[CPU_WORD_SIZE] = '\0'; //replace \n with \0
|
||||||
ram[j] = strtoul(tempS,NULL,2);
|
ram[j] = strtoul(tempS,NULL,2);
|
||||||
j++;
|
j++;
|
||||||
}
|
}
|
||||||
|
12
src/toy.h
12
src/toy.h
@ -11,7 +11,7 @@ extern const uint16_t * const ACCU; //read only access to accu
|
|||||||
/**
|
/**
|
||||||
* print_instructionSet(): prints the cpu instruction set.
|
* print_instructionSet(): prints the cpu instruction set.
|
||||||
* This is a user help function and can be activated via
|
* This is a user help function and can be activated via
|
||||||
* the -h paramter.
|
* the -h parameter.
|
||||||
* Return: none
|
* Return: none
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -34,22 +34,22 @@ void print_instruction(uint8_t opcode);
|
|||||||
int initialise_ram(uint16_t *ram, int argc, char **argv );
|
int initialise_ram(uint16_t *ram, int argc, char **argv );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* get_opcode(): segments the mashine code in the OP-Code.
|
* get_opcode(): segments machine code as OP-Code.
|
||||||
* Return: 4 bit OP-Code.
|
* Return: 4-bit OP-Code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
uint8_t get_opcode(uint16_t instruction);
|
uint8_t get_opcode(uint16_t instruction);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* get_data(): gets the addressed data from the RAM.
|
* get_data(): gets the addressed data from RAM.
|
||||||
* Return: the 12 bit data address.
|
* Return: the 12-bit data address.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
uint16_t get_data(uint16_t instruction);
|
uint16_t get_data(uint16_t instruction);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* execute(): executes the toy-CPU instruction.
|
* execute(): executes the toy-CPU instruction.
|
||||||
* This function implements the CPU instruction set,
|
* This function implements the CPU instruction set;
|
||||||
* use print_instructionSet() for an overview.
|
* use print_instructionSet() for an overview.
|
||||||
* Return: true if there is a jump.
|
* Return: true if there is a jump.
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user