31 lines
718 B
C
31 lines
718 B
C
#include "cpu.h"
|
|
#include <stdio.h>
|
|
|
|
static void printBinary(int num) {
|
|
if (num > 1) {
|
|
printBinary(num / 2);
|
|
}
|
|
printf("%d", num % 2);
|
|
}
|
|
|
|
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);
|
|
}
|
|
|
|
// TODO
|
|
|
|
return 0;
|
|
}
|