criscv/src/instruction_executor.c

32 lines
718 B
C
Raw Normal View History

2024-10-15 13:30:45 +02:00
#include "cpu.h"
#include <stdio.h>
static void printBinary(int num) {
if (num > 1) {
printBinary(num / 2);
}
printf("%d", num % 2);
}
2024-10-15 13:30:45 +02:00
int execute_instruction_on_cpu(CPU *cpu, uint32_t instruction) {
AddressSpace *addressSpace = cpu->addressSpace;
cpu->registers[0] = 0; // x0 is always 0
uint8_t opcode = instruction & 0x7F;
uint8_t rd = instruction >> 7 & 0x1F;
if (opcode != 0) {
printf("\nPC: %d\n", cpu->programCounter);
printf("Instruction: ");
printBinary(instruction);
printf("\nOpcode: 0x%X (", opcode);
printBinary(opcode);
printf(")\n");
printf("Dest. reg.: x%d\n", rd);
}
2024-10-15 13:30:45 +02:00
// TODO
return 0;
}