Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include "StackLib.h"
- #include <math.h>
- #define LABELS_COUNT 32
- #define MEMORY_SIZE 128
- enum command_list
- {
- CMD_PUSH = 1,
- CMD_ADD = 3,
- CMD_MUL = 4,
- CMD_DIV = 5,
- CMD_SUB = 6,
- CMD_POP = 20,
- CMD_POPsq = 21,
- CMD_POPax = 22,
- CMD_POPbx = 23,
- CMD_POPcx = 24,
- CMD_POPdx = 25,
- CMD_JMP = 100,
- CMD_JE = 101,
- CMD_JNE = 102,
- CMD_JA = 103,
- CMD_JAE = 104,
- CMD_JB = 105,
- CMD_JBE = 106,
- CMD_OUT = 7,
- CMD_SQRT = 8,
- CMD_IN = 9
- };
- struct CPU
- {
- double ax;
- double bx;
- double cx;
- double dx;
- int * memory;
- struct * Stack;
- };
- int main ()
- {
- struct CPU MY_CPU;
- initialize_CPU(&MY_CPU);
- FILE * bytecod = fopen ("bytecod.txt", "r");
- int size = fsize(FILE * bytecod);
- int * commands = (int *) calloc(size, sizeof(int));
- int * labels = (int *) calloc(LABELS_COUNT, sizeof(int));
- char symbol = '\0';
- int label = 0;
- mem_labels(bytecod, labels);
- }
- int initialize_CPU(struct CPU * MY_CPU)
- {
- /*
- * МЕСТО ДЛЯ ПРОВЕРОК
- */
- MY_CPU -> memory = (int *) calloc (MEMORY_SIZE, sizeof(int));
- MY_CPU -> ax = 0;
- MY_CPU -> bx = 0;
- MY_CPU -> cx = 0;
- MY_CPU -> dx = 0;
- MY_CPU - = init_stack()
- }
- int fsize(FILE * bytecode)
- {
- if (bytecod == NULL )
- {
- return -1;
- }
- int size = 0;
- int curpos = 0;
- curpos = ftell(bytecod);
- fseek (bytecod, 0, SEEK_END);
- size = ftell(bytecod);
- fseek (bytecod, 0, curpos);
- return size;
- }
- int mem_labels (FILE * bytecod, int * labels)
- {
- /*
- * МЕСТО ДЛЯ ПРОВЕРОК
- */
- char symbol = '\0';
- int number_of_label = 0;
- int number_of_command = 0;
- initialize_array(labels);
- while(fscanf(bytecod, "%c", &symbol) != EOF)
- {
- if (symbol == ':')
- {
- fscanf(bytecod, "%d", &number_of_label);
- labels[number_of_label] = number_of_command;
- }
- else
- number_of_command += 1;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement