rework spelling

This commit is contained in:
lux 2017-10-04 16:23:55 +02:00
parent 21b0c13056
commit 845adb0f58
4 changed files with 30 additions and 30 deletions

View File

@ -2,27 +2,27 @@
#define DEBUG_H
/**
* get2compl(): interprets the transfer value as tow's complement
* Return: tow's complement value between -32768 and 32767
* get2compl(): interprets the transfer value as two's complement
* Return: two's complement value between -32768 and 32767
*/
int32_t get2compl(uint16_t value);
/**
* fprintBits(): interprets an integer value as a binary pattern.(little endian)
* if you pass the datatype and the address of an integer,
* the funktion will supply the binary representation.
* (give "stdout" as the last parameter for standard output,
* otherwise hand over a filepointer)
* fprintBits(): interprets an integer value as a binary pattern.(Little-Endian)
* if you transfer the datatype and the address of an integer,
* the function will supply the binary representation.
* (enter "stdout" as the last parameter for standard output,
* otherwise enter a file pointer)
* Return: none
*/
void fprintBits(size_t const size, void const * const ptr, FILE *file_pointer);
/**
* makeHexDump(): writes the RAM content to a textfile.
* if you pass true to base_2, binary code is written to the textfile,
* otherwise hexcode.
* makeHexDump(): writes the RAM content to a text file.
* if you enter true for base_2, binary code is written to the text file,
* otherwise hex code.
* Return: none
*/

View File

@ -17,9 +17,9 @@ int main(int argc, char *argv[])
uint16_t ir=0; //Instruction Register
uint8_t op_code; //CPU Operation Code
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)
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
" 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
(-1 in case of error,
else number of correct read worts)*/
else number of correctly read words)*/
while(run)
{
ir = ram[pc]; //get instruction from RAM
op_code = get_opcode(ir); //determine the instruction form
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
printf("\ninstruction:\t");
fprintBits(sizeof(*ram), ram+pc,stdout);
@ -45,11 +45,11 @@ int main(int argc, char *argv[])
printf("\ninstruction result:\n");
//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);
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
printf("ACCU: %d\n",get2compl(*ACCU));

View File

@ -32,10 +32,10 @@ void print_instructionSet(void)
"\t| OP-CODE |\t\tADDRESS\t |\n"
"\t---------------------------------------\n\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"
"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");
printf("This is an interpreter for the Koopman_TOY_CPU by\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 )
{
//open and check the input stream
//opens and checks the input stream
FILE *fp;
int int_cache=0;
size_t j=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)
{
@ -96,7 +96,7 @@ int initialise_ram(uint16_t *ram, int argc, char **argv )
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;
}
@ -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))
{
fprintf(stderr,"%s","input file has incorrect machine-word size !\n");
fprintf(stderr,"%s","input file has word length error(s) !\n");
fclose(fp);
return -1;
}
@ -125,7 +125,7 @@ int initialise_ram(uint16_t *ram, int argc, char **argv )
tempS[i] = int_cache;
}
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);
j++;
}

View File

@ -11,7 +11,7 @@ extern const uint16_t * const ACCU; //read only access to accu
/**
* print_instructionSet(): prints the cpu instruction set.
* This is a user help function and can be activated via
* the -h paramter.
* the -h parameter.
* Return: none
*/
@ -25,7 +25,7 @@ void print_instructionSet(void);
void print_instruction(uint8_t opcode);
/**
* initialise_ram(): reads inputstream into the toy-ram.
* initialise_ram(): reads input stream into the toy-ram.
* Return:
* the number of successfully read machine words,
* -1 in case of error.
@ -34,22 +34,22 @@ void print_instruction(uint8_t opcode);
int initialise_ram(uint16_t *ram, int argc, char **argv );
/**
* get_opcode(): segments the mashine code in the OP-Code.
* Return: 4 bit OP-Code.
* get_opcode(): segments machine code as OP-Code.
* Return: 4-bit OP-Code.
*/
uint8_t get_opcode(uint16_t instruction);
/**
* get_data(): gets the addressed data from the RAM.
* Return: the 12 bit data address.
* get_data(): gets the addressed data from RAM.
* Return: the 12-bit data address.
*/
uint16_t get_data(uint16_t 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.
* Return: true if there is a jump.
*/