lab5: add assembler and dynamic pipeline system emulator
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
#pragma once
|
||||
|
||||
#include <array>
|
||||
#include <vector>
|
||||
#include <cstdint>
|
||||
|
||||
#include "config.h"
|
||||
|
||||
namespace DynamicPipeline {
|
||||
|
||||
enum CommandType : char
|
||||
{
|
||||
ADD,
|
||||
SUB,
|
||||
MUL,
|
||||
DIV,
|
||||
POW,
|
||||
CMD_COUNT
|
||||
};
|
||||
|
||||
struct Command
|
||||
{
|
||||
enum CommandType t;
|
||||
uint16_t op1;
|
||||
uint16_t op2;
|
||||
uint16_t res;
|
||||
|
||||
Command(enum CommandType t, uint16_t op1, uint16_t op2, uint16_t res)
|
||||
: t(t), op1(op1), op2(op2), res(res)
|
||||
{
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
struct MemCell
|
||||
{
|
||||
double v;
|
||||
int ready;
|
||||
};
|
||||
|
||||
class System
|
||||
{
|
||||
private:
|
||||
std::vector<Command> *program_memory;
|
||||
std::array<MemCell, DYN_PIPELINE_MEM_SIZE> data_memory;
|
||||
std::array<int, CMD_COUNT> delays {2, 2, 5, 5, 9};
|
||||
std::array<int, DYN_PIPELINE_LAYERS> layer_cmd {-1};
|
||||
unsigned int pc {0};
|
||||
unsigned int system_time;
|
||||
|
||||
void print_pipeline(void) const;
|
||||
bool pipeline_empty(void) const;
|
||||
bool next_instruction(void) const;
|
||||
bool instruction_ready(void) const;
|
||||
void step(void);
|
||||
|
||||
public:
|
||||
void init(const std::vector<Command> * const prg, const std::array<double, DYN_PIPELINE_MEM_SIZE>& mem, const int init_mem_size);
|
||||
void run(void);
|
||||
};
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user