cpu.c 700 B

123456789101112131415161718192021222324252627282930
  1. unsigned int registers[32];
  2. unsigned int pc;
  3. unsigned int pipeline[5];
  4. //R I S B U J
  5. #define OP(inst) ((inst >> 0) & 0x00007F)
  6. //R I U J
  7. #define RD(inst) ((inst >> 7) & 0x00001F)
  8. // R I S B
  9. #define FN3(inst) ((inst >> 12) & 0x000007)
  10. // R I S B
  11. #define RS1(inst) ((inst >> 15) & 0x00001F)
  12. // R S B
  13. #define RS2(inst) ((inst >> 20) & 0x00001F)
  14. // R
  15. #define FN7(inst) ((inst >> 25) & 0x00007F)
  16. // I
  17. #define IIM(inst) ((inst >> 20) & 0x000FFF)
  18. // S
  19. #define SI(inst) (((inst >> 7) & 0x00001F)|((inst >> 20) & 0x00000000))
  20. // B
  21. #define SI2(inst) ((inst >> 25) & 0x00001F)
  22. #define UIM(inst) ((inst >> 12) & 0x0FFFFF)
  23. void step()
  24. {
  25. pc += 4;
  26. pipeline[0] = memRead(pc);
  27. }