14 #ifndef CPPRISC16_CPPRISC16_CPPRISC16_HPP_ 15 #define CPPRISC16_CPPRISC16_CPPRISC16_HPP_ 30 #define i_beq(a, b, label) { \ 31 assert(a < cpprisc16::nb_registers); \ 32 assert(b < cpprisc16::nb_registers); \ 34 ++cpprisc16::nb_executed; \ 35 if (cpprisc16::registers[a] == cpprisc16::registers[b]) { goto label; } \ 92 extern word16_t
memory[256];
112 i_add(
unsigned int result,
unsigned int a,
unsigned int b);
127 i_addi(
unsigned int result,
unsigned int a, immed_t immed6);
144 i_jalr(
unsigned int result,
unsigned int a);
156 i_lui(
unsigned int result, immed_t immed10);
171 i_lw(
unsigned int result,
unsigned int a, immed_t immed6);
180 i_nand(
unsigned int result,
unsigned int a,
unsigned int b);
195 i_sw(
unsigned int a,
unsigned int result, immed_t immed6);
211 p_halt(
bool print =
true);
227 p_movi(
unsigned int result, immed_t immed);
399 #endif // CPPRISC16_CPPRISC16_CPPRISC16_HPP_ void p_movi(unsigned int result, immed_t immed)
(MOV Immediate) R[result] <– immed
void i_jalr(unsigned int result, unsigned int a)
(Jump And Link using Register) In the real RiSC16: R[result] <– PC + 1 (where PC = Program Counter)...
void println_memory(unsigned int size)
Print memory items.
void clear_memory()
Reset to 0 all memory items and mark them as not used.
void print_value32(std::uint32_t n)
Print to stdout the 32 bits value n: hexadecimal representation = binary = decimal = signed decimal (...
void p_reset()
In the real RiSC16: R[result] <– PC + 1 (where PC = Program Counter), PC <– 0 (jump to 0) but impos...
void println_infos()
Print to stdout the number of executed instructions.
void println_value32(std::uint32_t n)
Print to stdout the 32 bits value n: hexadecimal representation = binary = decimal = signed decimal...
word16_t memory[256]
Memory items.
std::uint16_t word16_t
Type for register and memory items.
void i_addi(unsigned int result, unsigned int a, immed_t immed6)
(ADD Immediate) R[result] <– R[a] + immed6
void println_registers()
Print all registers items.
void println_reg(unsigned int a)
Print the register R[a].
std::uint16_t immed_t
Type for immediate value.
void print_mem(unsigned int i)
Print ith memory item M[i] (without newline).
void i_add(unsigned int result, unsigned int a, unsigned int b)
R[result] <– R[a] + R[b].
const unsigned int size_memory
Size of the memory: 256 word16_t items.
word16_t registers[8]
Registers.
const unsigned int nb_registers
Number of registers: 8 word16_t items.
unsigned int after_last_memory_acceded
Index following the last memory item used.
void i_sw(unsigned int a, unsigned int result, immed_t immed6)
(Store Word) Memory[R[result] + immed6] <– R[a]
void println_reg2(unsigned int a2, unsigned int a1)
Print the 32 bits value of R[a2]:R[a1].
uint64_t nb_executed
Number of instructions executed.
void println_mem(unsigned int i)
Print ith memory item M[i].
void println_value16(std::uint16_t n)
Print to stdout the 16 bits value n: hexadecimal representation = binary = decimal = signed decimal...
void print_reg(unsigned int a)
Print the register R[a] (without newline).
void print_value16(std::uint16_t n)
Print to stdout the 16 bits value n: hexadecimal representation = binary = decimal = signed decimal (...
void clear_registers()
Reset to 0 all registers.
void p_halt(bool print)
If print then call println_all()
void print_reg2(unsigned int a2, unsigned int a1)
Print the 32 bits value of R[a2]:R[a1] (without newline).
void println_all()
Print infos, registers and memory (if used).
void clear_nb_executed()
Reset the number of executed instructions.
void i_nand(unsigned int result, unsigned int a, unsigned int b)
R[result] <– R[a] NAND R[b] (== ~(a & b))
void i_lw(unsigned int result, unsigned int a, immed_t immed6)
(Load Word) R[result] <– Memory[R[a] + immed6]
void i_lui(unsigned int result, immed_t immed10)
(Load Upper Immediate) R[result] <– immed10 << 6