diff --git a/commands_into_num.h b/commands_into_num.h new file mode 100644 index 0000000..77e2a06 --- /dev/null +++ b/commands_into_num.h @@ -0,0 +1,31 @@ +const int CAPACITY = 10; +const int MAX_LEN_OF_WORD = 100; +const int LEFT_CONSTANT = 0xFEDCBA; +const int RIGHT_CONSTANT = 0xFEDCBA; +const int MAX_SIZE_ARR = 1000; +const int SIZE_OF_REG = 16; + +int arr[MAX_SIZE_ARR] = {0}, arr_of_steps[MAX_SIZE_ARR] = {0}; + +enum WasFileRead { + NO, + YES +}; + +int CompareStringWithCommand(char *string); +int LooksForNumInString(char* str, int* numm); +void RemoveSymbOfNewStr(char *string); +bool Push(char** inf, int i, int* sum_of_steps); +void ProgrammForFileInput(const char* filee_name, char ** inf, int* amount_of_str); +WasFileRead OpenAndCheckFileForReading(FILE** filee, const char* filee_name); +ssize_t MyOwnGetline(char **lineptr, size_t *buff_size, FILE *filestr); +void OutputInFile(int* arr, int i); +int LooksForReg(char* str); + + + +const char *ArrayOfCommands[] = {"push ", "add", "sub", "div", "mul", "sqrt", "out", "hlt", "popr ", "pushr"}; + +const int amount_of_commands = sizeof(ArrayOfCommands)/sizeof(ArrayOfCommands[0]); +const int first_reg_command = 8; +const int len_for_strncmp = strlen("pushr"); \ No newline at end of file diff --git a/commands_into_numbers.cpp b/commands_into_numbers.cpp new file mode 100644 index 0000000..51b2be4 --- /dev/null +++ b/commands_into_numbers.cpp @@ -0,0 +1,205 @@ +/*программа переводит команды из файла в числа*/ +#include +#include +#include +#include + +#include "commands_into_num.h" +int main(const int argc, const char* argv[]) +{ + const char* filee_name = argc > 0? argv[1]: ""; + FILE* filee = nullptr; + + int amount_of_str = 0, sum_of_steps = 0, counter = 0; + char* inf[MAX_SIZE_ARR] = {0}; + ProgrammForFileInput(filee_name, inf, &amount_of_str); + bool prm_for_while = true; + + while(prm_for_while && counter < amount_of_str) + prm_for_while = Push(inf, counter++, &sum_of_steps); + + OutputInFile(arr, counter); + return 0; +} + +void OutputInFile(int* arr, int i) +{ + /*FILE* output_file = fopen("datasm", "w"); если я пытаюсь открыть файл, программа зависает...(( + а так то вывод должен быть в файл, но пока есть только в терминал*/ + int sum = 0; + for (int j = 0; j < i; j++) + { + if (arr_of_steps[j] == 1) + printf("%d\n", arr[j + sum]); + else if (arr_of_steps[j] == 2) + { + printf("%d ", arr[j + sum]); + sum++; + printf("%d\n", arr[j + sum]); + } + } +} + +void ProgrammForFileInput(const char* filee_name, char ** inf, int* amount_of_str) +{ + FILE* filee = nullptr; + if (!OpenAndCheckFileForReading(&filee, filee_name)) + return; + else + { + int counterr = 0, check_len = 0; + size_t buff_size = MAX_LEN_OF_WORD; + while (check_len != -1) + { + char *lineptr = (char *)calloc(buff_size, sizeof(char)); + check_len = MyOwnGetline(&lineptr, &buff_size, filee); + inf[counterr] = lineptr; + counterr++; + } + *amount_of_str = counterr; + } + +} + +ssize_t MyOwnGetline(char **lineptr, size_t *buff_size, FILE *filestr) +{ + char ch = 0, i = 0; + char *buff = *lineptr; + if (filestr == nullptr) + return -1; + while ((ch = getc(filestr)) != '\n' && ch != EOF) + { + if ((int)*buff_size < i + 1) + { + char *new_buff = (char*) realloc(buff, sizeof(char) * (*buff_size) * 2); + if (new_buff = nullptr) + { + return i; + } + } + *(buff + i) = ch; + i++; + } + *buff_size = strlen(buff); + char *new_new_buff = (char*)realloc(buff, sizeof(char) * (*buff_size) * 2); + *(buff + i) = '\n'; + *(buff + i + 1) = '\0'; + *lineptr = buff; + if (i == 0) + return -1; + else + return i; +} + +WasFileRead OpenAndCheckFileForReading(FILE** filee, const char* filee_name)// +{ + *filee = fopen(filee_name, "rb"); + if (*filee == nullptr) + { + printf("File %s didn't open((\n", filee_name); + return NO; + } + return YES; +} + +bool Push(char** inf, int i, int* sum_of_steps) +{ + int numm = 0, counter = 0; + if (*(inf + i) == nullptr) + return false; + int num_of_func = CompareStringWithCommand(*(inf + i)); + if (num_of_func == 0) + { + arr[i + *sum_of_steps] = num_of_func; + counter = LooksForNumInString(*(inf + i), &numm); + if (counter > 0) + { + arr_of_steps[i] = 2; + (*sum_of_steps)++; + arr[i + *sum_of_steps] = numm; + } + else + arr_of_steps[i] = 1; + return true; + } + else if (num_of_func > 0 && num_of_func < first_reg_command) + { + arr[i + *sum_of_steps] = num_of_func; + arr_of_steps[i] = 1; + return true; + } + else if (num_of_func >= first_reg_command) + { + arr[i + *sum_of_steps] = num_of_func; + counter = LooksForReg(*(inf + i)); + if (counter >= 0) + { + arr_of_steps[i] = 2; + (*sum_of_steps)++; + arr[i + *sum_of_steps] = numm; + } + return true; + } + return false; +} + +int LooksForNumInString(char* str, int* numm) +{ + int i = 0;// + int num = 0, counter = 0; + while (str[i] != '\n') + { + if (isdigit(str[i])) + { + num = num * 10 + (int)str[i] - '0'; + counter++; + i++; + continue; + } + else if (counter != 0 && !isdigit(str[i])) + break; + i++; + } + if (counter != 0) + { + *numm = num; + return 1; + } + return 0; +} + +int CompareStringWithCommand(char *string) +{ + RemoveSymbOfNewStr(string); + int len = strlen(string); + if (len > len_for_strncmp) + len = len_for_strncmp; + for (int i = 0; i < amount_of_commands; i++) + { + if (strncmp(string, ArrayOfCommands[i], len) == 0) + { + return i; + } + } + return -1; +} + +void RemoveSymbOfNewStr(char *string) +{ + for (int i = 0; i < strlen(string); i++) + { + if (string[i] =='\n') + string[i - 1] = '\0'; + } +} + +int LooksForReg(char* str) +{ + int len = strlen(str) - 2;///// + int num = (int)str[len] - (int)'a'; + if (num >= 0 && num < SIZE_OF_REG) + { + return num; + } + return -1; +} diff --git a/compare_and_run_functions.cpp b/compare_and_run_functions.cpp new file mode 100644 index 0000000..36c0bb6 --- /dev/null +++ b/compare_and_run_functions.cpp @@ -0,0 +1,95 @@ +#include +#include +#include "compare_and_run_functions.h" + +int CompareStringWithCommandForAsm(int num) +{ + //RemoveSymbOfNewStr(string); + for (int i = 0; i < amount_of_commands; i++) + { + if (i == num) + return i; + } + return -1; +} + +int CompareStringWithCommand(char *string) +{ + RemoveSymbOfNewStr(string); + int len = strlen(string); + if (len > len_for_strncmp) + len = len_for_strncmp; + for (int i = 0; i < amount_of_commands; i++) + { + if (strncmp(string, ArrayOfCommands[i].command, len) == 0)// + return i; + } + return -1; +} + +bool RunFuncForAsm(spu_t* spu) +{ + int numm = 0, counter = 0; + stack_t* stack = spu->stack; + int ip = spu->ip; + int num_of_func = spu->code[ip + spu->amount_of_steps]; + + if (num_of_func == 0) + { + numm = spu->code[ip + spu->amount_of_steps + 1]; + StackVerify(stack, numm); + ArrayOfCommands[num_of_func].pt(spu, numm); + return true; + } + else if (num_of_func > 0 && num_of_func != num_of_hlt) + { + StackVerify(stack); + ArrayOfCommands[num_of_func].pt(spu, numm); + return true; + } + else if (num_of_func != num_of_hlt) + { + numm = 1; + StackVerify(stack, numm); + return false; + } + return false; +} + +bool RunFunc(spu_t* spu, char* inf) +{ + int numm = 0, counter = 0; + int comp = strncmp(inf, "hlt", MAX_LEN_OF_WORD); + + int num_of_func = CompareStringWithCommand(inf); + if (num_of_func == 0) + { + counter = LooksForNumInString(inf, &numm); + StackVerify(spu->stack, numm); + if (counter > 0) + ArrayOfCommands[num_of_func].pt(spu, numm); + return true; + } + else if (num_of_func > 0 && comp != 0 && num_of_func < first_reg_command) + { + StackVerify(spu->stack); + ArrayOfCommands[num_of_func].pt(spu, numm); + return true; + } + else if (num_of_func >= first_reg_command)// + { + int reg = LooksForReg(inf); + if (reg >= 0) + { + ArrayOfCommands[num_of_func].pt(spu, reg); + return true; + } + } + else if (comp != 0) + { + numm = 1; + StackVerify(spu->stack, numm); + return false; + } + return false; +} \ No newline at end of file diff --git a/compare_and_run_functions.h b/compare_and_run_functions.h new file mode 100644 index 0000000..5ddef3e --- /dev/null +++ b/compare_and_run_functions.h @@ -0,0 +1,76 @@ +const int MAX_LEN_OF_WORD = 100; +const int first_reg_command = 8; + +enum StackErr_t { + NO_ERRORS, + MEMORY_ALLOCATION, + NULLPTR, + CAPACITY_LESS_THAN_SIZE, + CAPACITY_OR_SIZE_LESS_THAN_ZERO, + NO_PARAMETER, + ATTACK_FROM_THE_LEFT, + ATTACK_FROM_THE_RIGHT, + ERROR_COMAND +}; + +struct stack_t { + int* data; + int size; + int capacity; + StackErr_t error; +}; + +struct spu_t { + int* code; + stack_t* stack; + int ip; + int* steps; + int amount_of_steps; + int* regs; +}; + +typedef void (*function_ptr)(spu_t*, int); + +struct commands_t { + const char* command; + function_ptr pt; + const char* description; +}; + +void StackPush(spu_t* spu, int num); +void StackDestroy(spu_t* spu, int n = NULL); +void StackPop(spu_t* spu, int n = NULL); +void AddNumbers(spu_t* spu, int n = NULL); +void DifferenceOfNumbers(spu_t* spu, int n = NULL); +void QuotientOfNumbers(spu_t* spu, int n = NULL); +void MultiplyingNumbers(spu_t* spu, int n = NULL); +void SquareRootOfNumber(spu_t* spu, int n = NULL); +void Popr(spu_t* spu, int num); +void Pushr(spu_t* spu, int reg); + +commands_t ArrayOfCommands[] = {{"push ", StackPush, "pushing a number onto the stack"}, + {"add", AddNumbers, "adding numbers"}, + {"sub", DifferenceOfNumbers, "number difference"}, + {"div", QuotientOfNumbers, "quotient of numbers"}, + {"mul", MultiplyingNumbers, "multiplying numbers"}, + {"sqrt", SquareRootOfNumber, "square root calculation"}, + {"out", StackPop, "returns the value removed from the stack"}, + {"hlt", StackDestroy, "ends the loop"}, + {"popr ", Popr, "add number in register"}, + {"pushr", Pushr, "delete number from register"}}; + +const int amount_of_commands = sizeof(ArrayOfCommands)/sizeof(ArrayOfCommands[0]); + +const int num_of_hlt = 7; + +bool StackVerify(stack_t *stk, int prm = -1); +int CompareStringWithCommand(char *string); +int LooksForNumInString(char* str, int* numm); +int LooksForReg(char* str); +void RemoveSymbOfNewStr(char *string); +bool RunFunc(spu_t* spu, char* inf); +bool RunFuncForAsm(spu_t* spu); + + +const int len_for_strncmp = strlen("pushr"); + diff --git a/init.cpp b/init.cpp new file mode 100644 index 0000000..af87d84 --- /dev/null +++ b/init.cpp @@ -0,0 +1,52 @@ +#include +#include +#include "init.h" + +void StackInit(stack_t *stk, const int CAPACITY) +{ + StackVerify(stk); + stk->capacity = CAPACITY; + int *data = (int *)calloc(CAPACITY + 1, sizeof(int)); + + stk->data = data; + stk->data[0] = 0xFEDCBA; + stk->data[CAPACITY] = 0xFEDCBA; + stk->size = 0; + stk->error = NO_ERRORS; +} + +spu_t SpuInit(stack_t *stk) +{ + spu_t spu = {}; + spu.stack = stk; + spu.ip = 0; + int regs[SIZE_OF_REG] = {0}; + spu.regs = regs; + int steps[MAX_SIZE_OF_CODE] = {0}; + spu.steps = steps; + spu.amount_of_steps = 0; + int code[MAX_SIZE_OF_CODE] = {0};///// + spu.code = code; + return spu; +} + +void FillSpu(spu_t* spu, char* inf) +{ + int ip = spu->ip; + spu->code[ip + spu->amount_of_steps] = atoi(inf); + int numm = 0; + int amount_of_prm = LooksForNumInStringForAsm(inf, &numm); + if (amount_of_prm == 1) + { + spu->amount_of_steps++; + spu->code[ip + spu->amount_of_steps] = numm; + spu->steps[ip] = 2; + spu->ip++; + } + else + { + spu->steps[ip] = 1; + spu->ip++; + } + +} diff --git a/init.h b/init.h new file mode 100644 index 0000000..1074f72 --- /dev/null +++ b/init.h @@ -0,0 +1,37 @@ +const int CAPACITY = 10; +const int SIZE_OF_REG = 16; +const int MAX_SIZE_OF_CODE = 100000; + +enum StackErr_t { + NO_ERRORS, + MEMORY_ALLOCATION, + NULLPTR, + CAPACITY_LESS_THAN_SIZE, + CAPACITY_OR_SIZE_LESS_THAN_ZERO, + NO_PARAMETER, + ATTACK_FROM_THE_LEFT, + ATTACK_FROM_THE_RIGHT, + ERROR_COMAND +}; + +struct stack_t { + int* data; + int size; + int capacity; + StackErr_t error; +}; + +struct spu_t { + int* code; + stack_t* stack; + int ip; + int* steps; + int amount_of_steps; + int* regs; +}; + +void StackInit(stack_t *stk, const int CAPACITY); +spu_t SpuInit(stack_t *stk); +bool StackVerify(stack_t *stk, int prm = -1); +int LooksForNumInStringForAsm(char* str, int* numm); +void FillSpu(spu_t* spu, char* inf); \ No newline at end of file diff --git a/input_and_output.cpp b/input_and_output.cpp new file mode 100644 index 0000000..3f9b348 --- /dev/null +++ b/input_and_output.cpp @@ -0,0 +1,34 @@ +#include +#include "input_and_output.h" + + +bool Input(spu_t* spu) +{ + StackVerify(spu->stack); + printf("enter the command and the value if necessary\n"); + char inf[MAX_LEN_OF_WORD] = {0}; + gets(inf); + return RunFunc(spu, inf); + +} + +void InputFromFile(FILE* filee, spu_t* spu) +{ + StackVerify(spu->stack); + char inf[MAX_LEN_OF_WORD] = {0}; + + fgets(inf, MAX_LEN_OF_WORD, filee); + while (*inf != 55 && *inf != EOF)/// + { + FillSpu(spu, inf); + fgets(inf, MAX_LEN_OF_WORD, filee); + } +} + +void OutputForUser(stack_t *stk) +{ + StackVerify(stk); + StackErr_t err = stk->error; + if (err != NO_ERRORS) + printf("%s\n", ArrayOfErrors[err].description); +} \ No newline at end of file diff --git a/input_and_output.h b/input_and_output.h new file mode 100644 index 0000000..ab8d888 --- /dev/null +++ b/input_and_output.h @@ -0,0 +1,50 @@ +const int MAX_LEN_OF_WORD = 100; + +enum StackErr_t { + NO_ERRORS, + MEMORY_ALLOCATION, + NULLPTR, + CAPACITY_LESS_THAN_SIZE, + CAPACITY_OR_SIZE_LESS_THAN_ZERO, + NO_PARAMETER, + ATTACK_FROM_THE_LEFT, + ATTACK_FROM_THE_RIGHT, + ERROR_COMAND +}; + +struct stack_t { + int* data; + int size; + int capacity; + StackErr_t error; +}; + +struct stack_err_t { + StackErr_t type; + const char* description; +}; + +struct spu_t { + int* code; + stack_t* stack; + int ip; + int* steps; + int amount_of_steps; + int* regs; +}; + +stack_err_t ArrayOfErrors[] = {{NO_ERRORS, "no errors"}, + {MEMORY_ALLOCATION, "memory allocation error"}, + {NULLPTR, "null pointer detected"}, + {CAPACITY_LESS_THAN_SIZE, "capacity less than size"}, + {CAPACITY_OR_SIZE_LESS_THAN_ZERO, "capacity or size less than zero (not enough numbers in stack)"}, + {NO_PARAMETER, "parameter was not entered"}, + {ATTACK_FROM_THE_LEFT, "problems with stack"}, + {ATTACK_FROM_THE_RIGHT, "problems with stack"}, + {ERROR_COMAND, "you entered a non-existent command"}}; + +bool StackVerify(stack_t *stk, int prm = -1); +bool RunFunc(spu_t* spu, char* inf); +void FillSpu(spu_t* spu, char* inf); +bool Input(spu_t* spu); +void InputFromFile(FILE* filee, spu_t* spu); \ No newline at end of file diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..3c42b70 --- /dev/null +++ b/main.cpp @@ -0,0 +1,37 @@ +/*это основная программа, ввод из файла: команды - числа, ввод из терминала - команды буквами*/ +#include +#include +#include +#include +#include +#include + +#include "main.h" + + +int main(const int argc, const char* argv[]) +{ + stack_t stk = {}; + StackInit(&stk, CAPACITY); + spu_t spu = SpuInit(&stk); + + const char* filee_name = argc > 0? argv[1]: ""; + if (filee_name != nullptr) + { + ProgramForFileInput(&spu, filee_name); + /*for (int i = 0; i < SIZE_OF_REG; i++) + printf("%d\n", regs[i]);*/ + return 0; + } + ProgramForTerminalInput(&spu); + /*for (int i = 0; i < SIZE_OF_REG; i++) + printf("%d\n", regs[i]);*/ + return 0; +} + + + + + + + diff --git a/main.h b/main.h new file mode 100644 index 0000000..c2c0ca6 --- /dev/null +++ b/main.h @@ -0,0 +1,35 @@ +const int CAPACITY = 10; + +enum StackErr_t { + NO_ERRORS, + MEMORY_ALLOCATION, + NULLPTR, + CAPACITY_LESS_THAN_SIZE, + CAPACITY_OR_SIZE_LESS_THAN_ZERO, + NO_PARAMETER, + ATTACK_FROM_THE_LEFT, + ATTACK_FROM_THE_RIGHT, + ERROR_COMAND +}; + +struct stack_t { + int* data; + int size; + int capacity; + StackErr_t error; +}; + +struct spu_t { + int* code; + stack_t* stack; + int ip; + int* steps; + int amount_of_steps; + int* regs; +}; + + +void StackInit(stack_t *stk, const int CAPACITY); +spu_t SpuInit(stack_t *stk); +void ProgramForTerminalInput(spu_t* spu); +void ProgramForFileInput(spu_t* spu, const char* filee_name); \ No newline at end of file diff --git a/o b/o deleted file mode 100644 index 8d1c8b6..0000000 --- a/o +++ /dev/null @@ -1 +0,0 @@ - diff --git a/operations_with_stack.cpp b/operations_with_stack.cpp new file mode 100644 index 0000000..bedac3b --- /dev/null +++ b/operations_with_stack.cpp @@ -0,0 +1,179 @@ +#include +#include +#include "operations_with_stack.h" + +void AddNumbers(spu_t* spu, int n) +{ + stack_t* stk = spu->stack; + StackVerify(stk); + int size = stk->size; + int *data = stk->data; + + if (size - 1 <= 0) + { + stk->size = size - 2; + StackVerify(stk); + return; + } + + int last = data[size]; + int practically_last = data[size - 1]; + stk->size--; + stk->data[stk->size] = last + practically_last; +} + +void DifferenceOfNumbers(spu_t* spu, int n) +{ + stack_t* stk = spu->stack; + StackVerify(stk); + int size = stk->size; + int *data = stk->data; + + if (size - 1 <= 0) + { + stk->size = size - 2; + StackVerify(stk); + return; + } + + int last = data[size]; + int practically_last = data[size - 1]; + stk->size--; + stk->data[stk->size] = practically_last - last; +} + +void QuotientOfNumbers(spu_t* spu, int n) +{ + stack_t* stk = spu->stack; + StackVerify(stk); + int size = stk->size; + int *data = stk->data; + + if (size - 1 <= 0) + { + stk->size = size - 2; + StackVerify(stk); + return; + } + + int last = data[size]; + int practically_last = data[size - 1]; + stk->size--; + stk->data[stk->size] = practically_last / last; +} + +void MultiplyingNumbers(spu_t* spu, int n) +{ + stack_t* stk = spu->stack; + StackVerify(stk); + int size = stk->size; + int *data = stk->data; + + if (size - 1 <= 0) + { + stk->size = size - 2; + StackVerify(stk); + return; + } + + int last = data[size]; + int practically_last = data[size - 1]; + stk->size--; + stk->data[stk->size] = last * practically_last; +} + +void SquareRootOfNumber(spu_t* spu, int n) +{ + stack_t* stk = spu->stack; + StackVerify(stk); + stk->data[stk->size] = sqrt(stk->data[stk->size]); +} + +void StackPush(spu_t* spu, int num) +{ + stack_t* stk = spu->stack; + StackVerify(stk); + + int size = stk->size; + int *data = stk->data; + int capacity = stk->capacity; + + if (size >= capacity - 2) + { + int *new_ptr = (int *)realloc(stk->data, (capacity * 2 + 1) * sizeof(int)); + stk->data = new_ptr; + StackVerify(stk); + stk->capacity = capacity * 2; + stk->data[stk->capacity] = RIGHT_CONSTANT; + } + stk->size++; + stk->data[size + 1] = num; +} + +void Popr(spu_t* spu, int reg) +{ + stack_t* stk = spu->stack; + spu->regs[reg] = stk->data[stk->size]; + stk->size--; +} + +void StackPop(spu_t* spu, int n) +{ + stack_t* stk = spu->stack; + StackVerify(stk); + + int size = stk->size; + int *data = stk->data; + int capacity = stk->capacity; + + printf("last number from stack: %d\n", data[size]); + stk->data[size] = 0; + stk->size--; +} + +void Pushr(spu_t* spu, int reg) +{ + spu->regs[reg] = 0; +} + +void StackDump(spu_t* spu) +{ + stack_err_t ArrayOfErrors[] = {{NO_ERRORS, "no errors"}, + {MEMORY_ALLOCATION, "memory allocation error"}, + {NULLPTR, "null pointer detected"}, + {CAPACITY_LESS_THAN_SIZE, "capacity less than size"}, + {CAPACITY_OR_SIZE_LESS_THAN_ZERO, "capacity or size less than zero (not enough numbers in stack)"}, + {NO_PARAMETER, "parameter was not entered"}, + {ATTACK_FROM_THE_LEFT, "problems with stack"}, + {ATTACK_FROM_THE_RIGHT, "problems with stack"}, + {ERROR_COMAND, "you entered a non-existent command"}}; + stack_t* stk = spu->stack; + StackVerify(stk); + + int size = stk->size; + int *data = stk->data; + int capacity = stk->capacity; + + FILE* result; + result = fopen("result", "w"); + fprintf(result, "%s called from %s: %d\n" + "Stack [%p]\n" + "{\n size = %d\n" + " capacity = %d\n" + " errors: %s\n" + " data [%p]\n {\n", __func__, __FILE__, __LINE__, stk, size, capacity - 1, ArrayOfErrors[stk->error].description, data); + for (int i = 0; i < size; i++) + fprintf(result, " *[%d] = %d\n", i, data[i + 1]); + for (int i = size; i < capacity - 1; i++) + fprintf(result, " [%d] = %d (garbage)\n", i, data[i + 1]); + fprintf(result, " }\n}\n"); +} + +void StackDestroy(spu_t* spu, int n) +{ + stack_t* stk = spu->stack; + StackVerify(stk); + + free(stk->data); + stk->data = NULL; +} \ No newline at end of file diff --git a/operations_with_stack.h b/operations_with_stack.h new file mode 100644 index 0000000..2626268 --- /dev/null +++ b/operations_with_stack.h @@ -0,0 +1,47 @@ +const int RIGHT_CONSTANT = 0xFEDCBA; + +enum StackErr_t { + NO_ERRORS, + MEMORY_ALLOCATION, + NULLPTR, + CAPACITY_LESS_THAN_SIZE, + CAPACITY_OR_SIZE_LESS_THAN_ZERO, + NO_PARAMETER, + ATTACK_FROM_THE_LEFT, + ATTACK_FROM_THE_RIGHT, + ERROR_COMAND +}; + +struct stack_t { + int* data; + int size; + int capacity; + StackErr_t error; +}; + +struct spu_t { + int* code; + stack_t* stack; + int ip; + int* steps; + int amount_of_steps; + int* regs; +}; + +struct stack_err_t { + StackErr_t type; + const char* description; +}; + + + +void AddNumbers(spu_t* spu, int n = NULL); +void DifferenceOfNumbers(spu_t* spu, int n = NULL); +void QuotientOfNumbers(spu_t* spu, int n = NULL); +void MultiplyingNumbers(spu_t* spu, int n = NULL); +void SquareRootOfNumber(spu_t* spu, int n = NULL); +bool StackVerify(stack_t *stk, int prm = -1); +void StackPush(spu_t* spu, int num); +void StackDump(spu_t* spu); +void StackDestroy(spu_t* spu, int n = NULL); +void StackPop(spu_t* spu, int n = NULL); \ No newline at end of file diff --git a/program_mode.cpp b/program_mode.cpp new file mode 100644 index 0000000..f34c743 --- /dev/null +++ b/program_mode.cpp @@ -0,0 +1,51 @@ +#include +#include "program_mode.h" + +void ProgramForTerminalInput(spu_t* spu) +{ + bool prm_for_while = true, prm_for_while1 = true; + while (prm_for_while && prm_for_while1) + { + prm_for_while = Input(spu); + Canary(spu->stack); + prm_for_while1 = StackVerify(spu->stack); + } + + OutputForUser(spu->stack); + StackDump(spu); + StackDestroy(spu); +} + +void ProgramForFileInput(spu_t* spu, const char* filee_name) +{ + bool prm_for_while = true, prm_for_while1 = true; + FILE* filee = nullptr; + + if (!OpenAndCheckFileForReading(&filee, filee_name)) + return; + + InputFromFile(filee, spu); + int *steps = spu->steps; + int counter = spu->ip + spu->amount_of_steps; + spu->ip = 0; + spu->amount_of_steps = 0; + + while (prm_for_while1 && spu->ip < counter) + { + int ip = spu->ip; + + if (spu->steps[ip] == 0) + break; + + RunFuncForAsm(spu); + Canary(spu->stack); + prm_for_while1 = StackVerify(spu->stack); + spu->ip++; + spu->amount_of_steps = spu->amount_of_steps + spu->steps[ip] - 1; + + } + + OutputForUser(spu->stack); + StackDump(spu); + StackDestroy(spu); +} \ No newline at end of file diff --git a/program_mode.h b/program_mode.h new file mode 100644 index 0000000..926d064 --- /dev/null +++ b/program_mode.h @@ -0,0 +1,45 @@ + +enum StackErr_t { + NO_ERRORS, + MEMORY_ALLOCATION, + NULLPTR, + CAPACITY_LESS_THAN_SIZE, + CAPACITY_OR_SIZE_LESS_THAN_ZERO, + NO_PARAMETER, + ATTACK_FROM_THE_LEFT, + ATTACK_FROM_THE_RIGHT, + ERROR_COMAND +}; + +struct stack_t { + int* data; + int size; + int capacity; + StackErr_t error; +}; + +struct spu_t { + int* code; + stack_t* stack; + int ip; + int* steps; + int amount_of_steps; + int* regs; +}; + +enum WasFileRead { + NO, + YES +}; + +void ProgramForTerminalInput(spu_t* spu); +void ProgramForFileInput(spu_t* spu, const char* filee_name); +bool Input(spu_t* spu); +void Canary(stack_t *stk); +void OutputForUser(stack_t *stk); +bool StackVerify(stack_t *stk, int prm = -1); +void StackDump(spu_t* spu); +void StackDestroy(spu_t* spu, int n = NULL); +WasFileRead OpenAndCheckFileForReading(FILE** filee, const char* filee_name); +void InputFromFile(FILE* filee, spu_t* spu); +bool RunFuncForAsm(spu_t* spu); \ No newline at end of file diff --git a/stack.cpp b/stack.cpp new file mode 100644 index 0000000..317f93f --- /dev/null +++ b/stack.cpp @@ -0,0 +1,486 @@ +/*это основная программа, ввод из файла: команды - числа, ввод из терминала - команды буквами*/ +#include +#include +#include +#include +#include +#include + +#include "stack.h" + + +int main(const int argc, const char* argv[]) +{ + stack_t stk = {}; + StackInit(&stk, CAPACITY); + spu_t spu = SpuInit(&stk); + + const char* filee_name = argc > 0? argv[1]: ""; + if (filee_name != nullptr) + { + ProgrammForFileInput(&spu, filee_name); + /*for (int i = 0; i < SIZE_OF_REG; i++) + printf("%d\n", regs[i]);*/ + return 0; + } + ProgrammForTerminalInput(&stk); + /*for (int i = 0; i < SIZE_OF_REG; i++) + printf("%d\n", regs[i]);*/ + return 0; +} + +void ProgrammForTerminalInput(stack_t *stk) +{ + bool prm_for_while = true, prm_for_while1 = true; + while (prm_for_while && prm_for_while1) + { + prm_for_while = Input(stk); + Canary(stk); + prm_for_while1 = StackVerify(stk); + } + + OutputForUser(stk); + StackDump(stk); + StackDestroy(stk); +} + +void ProgrammForFileInput(spu_t* spu, const char* filee_name) +{ + bool prm_for_while = true, prm_for_while1 = true; + FILE* filee = nullptr; + if (!OpenAndCheckFileForReading(&filee, filee_name)) + return; + while (prm_for_while && prm_for_while1) + { + prm_for_while = InputFromFile(filee, spu); + Canary(spu->stack); + prm_for_while1 = StackVerify(spu->stack); + } + + OutputForUser(spu->stack); + StackDump(spu->stack); + StackDestroy(spu->stack); +} + +WasFileRead OpenAndCheckFileForReading(FILE** filee, const char* filee_name)// +{ + *filee = fopen(filee_name, "rb"); + if (*filee == nullptr) + { + printf("File %s didn't open((\n", filee_name); + return NO; + } + return YES; +} + +void Canary(stack_t *stk) +{ + if (stk->data[0] != LEFT_CONSTANT) + stk->error = ATTACK_FROM_THE_LEFT; + else if (stk->data[stk->capacity] != RIGHT_CONSTANT) + stk->error = ATTACK_FROM_THE_LEFT; +} + +bool Input(stack_t *stk) +{ + StackVerify(stk); + printf("enter the command and the value if necessary\n"); + char inf[MAX_LEN_OF_WORD] = {0}; + gets(inf); + return RunFunc(stk, inf); + +} + +bool InputFromFile(FILE* filee, spu_t* spu) +{ + StackVerify(spu->stack); + char inf[MAX_LEN_OF_WORD] = {0}; + fgets(inf, MAX_LEN_OF_WORD, filee); + if (*inf == '\0' || *inf == EOF) + return false; + return RunFuncForAsm(spu->stack, inf); + +} + +bool RunFuncForAsm(stack_t *stk, char* inf) +{ + int numm = 0, counter = 0; + + int num_of_func = CompareStringWithCommandForAsm(inf); + if (num_of_func == 0) + { + counter = LooksForNumInStringForAsm(inf, &numm); + StackVerify(stk, numm); + if (counter > 0) + ArrayOfCommands[num_of_func].pt(stk, numm); + return true; + } + else if (num_of_func > 0 && atoi(inf) != num_of_hlt) + { + StackVerify(stk); + ArrayOfCommands[num_of_func].pt(stk, numm); + return true; + } + else if (atoi(inf) != num_of_hlt) + { + numm = 1; + StackVerify(stk, numm); + return false; + } + return false; +} + +bool RunFunc(stack_t *stk, char* inf) +{ + int numm = 0, counter = 0; + int comp = strncmp(inf, "hlt", MAX_LEN_OF_WORD);/// + + int num_of_func = CompareStringWithCommand(inf); + if (num_of_func == 0) + { + counter = LooksForNumInString(inf, &numm); + StackVerify(stk, numm); + if (counter > 0) + ArrayOfCommands[num_of_func].pt(stk, numm); + return true; + } + else if (num_of_func > 0 && comp != 0 && num_of_func < first_reg_command) + { + StackVerify(stk); + ArrayOfCommands[num_of_func].pt(stk, numm); + return true; + } + else if (num_of_func >= first_reg_command)// + { + int reg = LooksForReg(inf); + if (reg >= 0) + { + ArrayOfCommands[num_of_func].pt(stk, reg); + return true; + } + } + else if (comp != 0) + { + numm = 1; + StackVerify(stk, numm); + return false; + } + return false; +} + +int LooksForReg(char* str) +{ + int len = strlen(str) - 2;///// + int num = (int)str[len] - (int)'a'; + if (num >= 0 && num < SIZE_OF_REG) + { + return num; + } + return -1; +} + +int LooksForNumInStringForAsm(char* str, int* numm) +{ + int i = 1;// + int num = 0, counter = 0; + int num_of_command = atoi(str); + while (num_of_command > 0) + { + i++; + num_of_command = num_of_command / 10; + } + + while (str[i] != '\0') + { + if (isdigit(str[i])) + { + num = num * 10 + (int)str[i] - '0'; + counter++; + i++; + continue; + } + else if (counter != 0 && !isdigit(str[i])) + break; + i++; + } + if (counter != 0) + { + *numm = num; + return 1; + } + return 0; +} + +int LooksForNumInString(char* str, int* numm) +{ + int i = 0;// + int num = 0, counter = 0; + while (str[i] != '\0') + { + if (isdigit(str[i])) + { + num = num * 10 + (int)str[i] - '0'; + counter++; + i++; + continue; + } + else if (counter != 0 && !isdigit(str[i])) + break; + i++; + } + if (counter != 0) + { + *numm = num; + return 1; + } + return 0; +} + +int CompareStringWithCommandForAsm(char *string) +{ + RemoveSymbOfNewStr(string); + for (int i = 0; i < amount_of_commands; i++) + { + if (i == atoi(string)) + return i; + } + return -1; +} + +int CompareStringWithCommand(char *string) +{ + RemoveSymbOfNewStr(string); + int len = strlen(string); + if (len > len_for_strncmp) + len = len_for_strncmp; + for (int i = 0; i < amount_of_commands; i++) + { + if (strncmp(string, ArrayOfCommands[i].command, len) == 0)// + return i; + } + return -1; +} + +void RemoveSymbOfNewStr(char *string) +{ + for (int i = 0; i < strlen(string); i++) + { + if (string[i] =='\n') + string[i - 1] = '\0'; + } +} + +void StackInit(stack_t *stk, const int CAPACITY) +{ + StackVerify(stk); + stk->capacity = CAPACITY; + int *data = (int *)calloc(CAPACITY + 1, sizeof(int)); + + stk->data = data; + stk->data[0] = 0xFEDCBA; + stk->data[CAPACITY] = 0xFEDCBA; + stk->size = 0; + stk->error = NO_ERRORS; +} + +spu_t SpuInit(stack_t *stk) +{ + spu_t spu = {}; + spu.stack = stk; + spu.ip = 0; + spu.regs = regs; + int* steps = (int*)calloc(CAPACITY, sizeof(int)); + spu.steps = steps; + return spu; +} + +bool StackVerify(stack_t *stk, int prm) +{ + int size = stk->size; + int *data = stk->data; + int capacity = stk->capacity; + + if (stk == nullptr) + stk->error = NULLPTR; + else if (data == nullptr) + stk->error = MEMORY_ALLOCATION; + else if (size < 0 || capacity < 0) + stk->error = CAPACITY_OR_SIZE_LESS_THAN_ZERO; + else if (size > capacity) + stk->error = CAPACITY_LESS_THAN_SIZE; + else if (prm == 0) + stk->error = NO_PARAMETER; + else if (prm == 1) + stk->error = ERROR_COMAND; + if (stk->error == NO_ERRORS) + return true; + return false; + +} + +void StackPush(stack_t *stk, int num) +{ + StackVerify(stk); + + int size = stk->size; + int *data = stk->data; + int capacity = stk->capacity; + + if (size >= capacity - 2) + { + int *new_ptr = (int *)realloc(stk->data, (capacity * 2 + 1) * sizeof(int)); + stk->data = new_ptr; + StackVerify(stk); + stk->capacity = capacity * 2; + stk->data[stk->capacity] = RIGHT_CONSTANT; + } + stk->size++; + stk->data[size + 1] = num; +} + +void Popr(stack_t *stk, int reg) +{ + regs[reg] = stk->data[stk->size]; + stk->size--; +} + +void StackPop(stack_t *stk, int n) +{ + StackVerify(stk); + + int size = stk->size; + int *data = stk->data; + int capacity = stk->capacity; + + printf("last number from stack: %d\n", data[size]); + stk->data[size] = 0; + stk->size--; +} + +void Pushr(stack_t *stk, int reg) +{ + regs[reg] = 0; +} + +void StackDump(stack_t *stk) +{ + StackVerify(stk); + + int size = stk->size; + int *data = stk->data; + int capacity = stk->capacity; + + FILE* result; + result = fopen("result", "w"); + fprintf(result, "%s called from %s: %d\n" + "Stack [%p]\n" + "{\n size = %d\n" + " capacity = %d\n" + " errors: %s\n" + " data [%p]\n {\n", __func__, __FILE__, __LINE__, stk, size, capacity - 1, ArrayOfErrors[stk->error].description, data); + for (int i = 0; i < size; i++) + fprintf(result, " *[%d] = %d\n", i, data[i + 1]); + for (int i = size; i < capacity - 1; i++) + fprintf(result, " [%d] = %d (garbage)\n", i, data[i + 1]); + fprintf(result, " }\n}\n"); +} + +void StackDestroy(stack_t *stk, int n) +{ + StackVerify(stk); + + free(stk->data); + stk->data = NULL; +} + +void AddNumbers(stack_t *stk, int n) +{ + StackVerify(stk); + int size = stk->size; + int *data = stk->data; + + if (size - 1 <= 0) + { + stk->size = size - 2; + StackVerify(stk); + return; + } + + int last = data[size]; + int practically_last = data[size - 1]; + stk->size--; + stk->data[stk->size] = last + practically_last; + /*stk->data[stk->size + 1] = 0; просто делает стек читабельнее (наверное, нуу мне так кажется) + стоит ли оставлять, если пользователь все равно не видит стек?*/ +} + +void DifferenceOfNumbers(stack_t *stk, int n) +{ + StackVerify(stk); + int size = stk->size; + int *data = stk->data; + + if (size - 1 <= 0) + { + stk->size = size - 2; + StackVerify(stk); + return; + } + + int last = data[size]; + int practically_last = data[size - 1]; + stk->size--; + stk->data[stk->size] = practically_last - last; +} + +void QuotientOfNumbers(stack_t *stk, int n) +{ + StackVerify(stk); + int size = stk->size; + int *data = stk->data; + + if (size - 1 <= 0) + { + stk->size = size - 2; + StackVerify(stk); + return; + } + + int last = data[size]; + int practically_last = data[size - 1]; + stk->size--; + stk->data[stk->size] = practically_last / last; +} + +void MultiplyingNumbers(stack_t *stk, int n) +{ + StackVerify(stk); + int size = stk->size; + int *data = stk->data; + + if (size - 1 <= 0) + { + stk->size = size - 2; + StackVerify(stk); + return; + } + + int last = data[size]; + int practically_last = data[size - 1]; + stk->size--; + stk->data[stk->size] = last * practically_last; +} + +void SquareRootOfNumber(stack_t *stk, int n) +{ + StackVerify(stk); + stk->data[stk->size] = sqrt(stk->data[stk->size]); +} + +void OutputForUser(stack_t *stk) +{ + StackVerify(stk); + StackErr_t err = stk->error; + if (err != NO_ERRORS) + printf("%s\n", ArrayOfErrors[err].description); +} \ No newline at end of file diff --git a/stack.h b/stack.h new file mode 100644 index 0000000..ad8c28c --- /dev/null +++ b/stack.h @@ -0,0 +1,108 @@ +const int CAPACITY = 10; +const int MAX_LEN_OF_WORD = 100; +const int LEFT_CONSTANT = 0xFEDCBA; +const int RIGHT_CONSTANT = 0xFEDCBA; +const int SIZE_OF_REG = 16; +const int first_reg_command = 8; +const int len_for_strncmp = strlen("pushr"); + +int regs[SIZE_OF_REG] = {0}; + +enum StackErr_t { + NO_ERRORS, + MEMORY_ALLOCATION, + NULLPTR, + CAPACITY_LESS_THAN_SIZE, + CAPACITY_OR_SIZE_LESS_THAN_ZERO, + NO_PARAMETER, + ATTACK_FROM_THE_LEFT, + ATTACK_FROM_THE_RIGHT, + ERROR_COMAND +}; + +struct stack_t { + int* data; + int size; + int capacity; + StackErr_t error; +}; + +struct stack_err_t { + StackErr_t type; + const char* description; +}; + +enum WasFileRead { + NO, + YES +}; + +struct spu_t { + int* code; + stack_t* stack; + int ip; + int* steps; + int* regs; +}; + +stack_err_t ArrayOfErrors[] = {{NO_ERRORS, "no errors"}, + {MEMORY_ALLOCATION, "memory allocation error"}, + {NULLPTR, "null pointer detected"}, + {CAPACITY_LESS_THAN_SIZE, "capacity less than size"}, + {CAPACITY_OR_SIZE_LESS_THAN_ZERO, "capacity or size less than zero (not enough numbers in stack)"}, + {NO_PARAMETER, "parameter was not entered"}, + {ATTACK_FROM_THE_LEFT, "problems with stack"}, + {ATTACK_FROM_THE_RIGHT, "problems with stack"}, + {ERROR_COMAND, "you entered a non-existent command"}}; + +typedef void (*function_ptr)(stack_t*, int); + +struct commands_t { + const char* command; + function_ptr pt; + const char* description; +}; + +void StackInit(stack_t *stk, const int CAPACITY); +spu_t SpuInit(stack_t *stk); +void StackPush(stack_t *stk, int num); +void StackDump(stack_t *stk); +void StackDestroy(stack_t *stk, int n = NULL); +void StackPop(stack_t *stk, int n = NULL); +bool StackVerify(stack_t *stk, int prm = -1); +bool Input(stack_t *stk); +int CompareStringWithCommand(char *string); +int LooksForNumInString(char* str, int* numm); +void AddNumbers(stack_t *stk, int n = NULL); +void DifferenceOfNumbers(stack_t *stk, int n = NULL); +void QuotientOfNumbers(stack_t *stk, int n = NULL); +void MultiplyingNumbers(stack_t *stk, int n = NULL); +void SquareRootOfNumber(stack_t *stk, int n = NULL); +void Canary(stack_t *stk); +bool RunFunc(stack_t *stk, char* inf); +void OutputForUser(stack_t *stk); +WasFileRead OpenAndCheckFileForReading(FILE** filee, const char* filee_name); +bool InputFromFile(FILE* filee, spu_t* spu); +void RemoveSymbOfNewStr(char *string); +void ProgrammForTerminalInput(stack_t *stk); +void ProgrammForFileInput(spu_t* spu, const char* filee_name); +int CompareStringWithCommandForAsm(char *string); +int LooksForNumInStringForAsm(char* str, int* numm); +bool RunFuncForAsm(stack_t *stk, char* inf); +int LooksForReg(char* str); +void Popr(stack_t *stk, int num); +void Pushr(stack_t *stk, int reg); + +commands_t ArrayOfCommands[] = {{"push ", StackPush, "pushing a number onto the stack"}, + {"add", AddNumbers, "adding numbers"}, + {"sub", DifferenceOfNumbers, "number difference"}, + {"div", QuotientOfNumbers, "quotient of numbers"}, + {"mul", MultiplyingNumbers, "multiplying numbers"}, + {"sqrt", SquareRootOfNumber, "square root calculation"}, + {"out", StackPop, "returns the value removed from the stack"}, + {"hlt", StackDestroy, "ends the loop"}, + {"popr ", Popr, "add number in register"}, + {"pushr", Pushr, "delete number from register"}}; + +const int amount_of_commands = sizeof(ArrayOfCommands)/sizeof(ArrayOfCommands[0]);// +const int num_of_hlt = 7; \ No newline at end of file diff --git a/verification.cpp b/verification.cpp new file mode 100644 index 0000000..0900435 --- /dev/null +++ b/verification.cpp @@ -0,0 +1,45 @@ +#include +#include "verification.h" + +WasFileRead OpenAndCheckFileForReading(FILE** filee, const char* filee_name)// +{ + *filee = fopen(filee_name, "rb"); + if (*filee == nullptr) + { + printf("File %s didn't open((\n", filee_name); + return NO; + } + return YES; +} + +void Canary(stack_t *stk) +{ + if (stk->data[0] != LEFT_CONSTANT) + stk->error = ATTACK_FROM_THE_LEFT; + else if (stk->data[stk->capacity] != RIGHT_CONSTANT) + stk->error = ATTACK_FROM_THE_LEFT; +} + +bool StackVerify(stack_t *stk, int prm) +{ + int size = stk->size; + int *data = stk->data; + int capacity = stk->capacity; + + if (stk == nullptr) + stk->error = NULLPTR; + else if (data == nullptr) + stk->error = MEMORY_ALLOCATION; + else if (size < 0 || capacity < 0) + stk->error = CAPACITY_OR_SIZE_LESS_THAN_ZERO; + else if (size > capacity) + stk->error = CAPACITY_LESS_THAN_SIZE; + else if (prm == 0) + stk->error = NO_PARAMETER; + else if (prm == 1) + stk->error = ERROR_COMAND; + if (stk->error == NO_ERRORS) + return true; + return false; + +} diff --git a/verification.h b/verification.h new file mode 100644 index 0000000..4b0eecc --- /dev/null +++ b/verification.h @@ -0,0 +1,26 @@ +const int LEFT_CONSTANT = 0xFEDCBA; +const int RIGHT_CONSTANT = 0xFEDCBA; + +enum WasFileRead { + NO, + YES +}; + +enum StackErr_t { + NO_ERRORS, + MEMORY_ALLOCATION, + NULLPTR, + CAPACITY_LESS_THAN_SIZE, + CAPACITY_OR_SIZE_LESS_THAN_ZERO, + NO_PARAMETER, + ATTACK_FROM_THE_LEFT, + ATTACK_FROM_THE_RIGHT, + ERROR_COMAND +}; + +struct stack_t { + int* data; + int size; + int capacity; + StackErr_t error; +}; \ No newline at end of file diff --git a/work_with_strings.cpp b/work_with_strings.cpp new file mode 100644 index 0000000..8c41713 --- /dev/null +++ b/work_with_strings.cpp @@ -0,0 +1,83 @@ +#include +#include +#include +#include +#include "work_with_strings.h" + +int LooksForReg(char* str) +{ + int len = strlen(str) - 2;///// + int num = (int)str[len] - (int)'a'; + if (num >= 0 && num < SIZE_OF_REG) + { + return num; + } + return -1; +} + +int LooksForNumInStringForAsm(char* str, int* numm) +{ + int i = 1;// + int num = 0, counter = 0; + int num_of_command = atoi(str); + while (num_of_command > 0) + { + i++; + num_of_command = num_of_command / 10; + } + + while (str[i] != '\0') + { + if (isdigit(str[i])) + { + num = num * 10 + (int)str[i] - '0'; + counter++; + i++; + continue; + } + else if (counter != 0 && !isdigit(str[i])) + break; + i++; + } + if (counter != 0) + { + *numm = num; + return 1; + } + return 0; +} + +int LooksForNumInString(char* str, int* numm) +{ + int i = 0;// + int num = 0, counter = 0; + while (str[i] != '\0') + { + if (isdigit(str[i])) + { + num = num * 10 + (int)str[i] - '0'; + counter++; + i++; + continue; + } + else if (counter != 0 && !isdigit(str[i])) + break; + i++; + } + if (counter != 0) + { + *numm = num; + return 1; + } + return 0; +} + + +void RemoveSymbOfNewStr(char *string) +{ + for (int i = 0; i < strlen(string); i++) + { + if (string[i] =='\n') + string[i - 1] = '\0'; + } +} \ No newline at end of file diff --git a/work_with_strings.h b/work_with_strings.h new file mode 100644 index 0000000..bcd7293 --- /dev/null +++ b/work_with_strings.h @@ -0,0 +1,6 @@ +const int SIZE_OF_REG = 16; + +int LooksForNumInString(char* str, int* numm); +void RemoveSymbOfNewStr(char *string); +int LooksForNumInStringForAsm(char* str, int* numm); +int LooksForReg(char* str);