Guest User

Untitled

a guest
Jul 16th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.23 KB | None | 0 0
  1. /* file: computer.h */
  2.  
  3.  
  4.  
  5. /* Round V to next greatest B boundary */
  6.  
  7. #define ROUND(V, B) (((int) V + (B-1)) & ~(B-1))
  8.  
  9.  
  10. /* Sign-extend a short to a long */
  11.  
  12. #define SIGN_EX(X) ((X) & 0x8000 ? (X) | 0xffff0000 : (X))
  13.  
  14.  
  15. #define K 1024
  16.  
  17. /* Type of a memory address. */
  18.  
  19. typedef unsigned long mem_addr;
  20.  
  21. /* Type of an instuction */
  22. typedef unsigned long instruction;
  23.  
  24. #define BYTES_PER_WORD 4 /* On the MIPS processor */
  25.  
  26. /* Type for a register */
  27. typedef long reg_word;
  28.  
  29. /* Register names */
  30. #define REG_SP 29
  31.  
  32.  
  33. /* Macros for disassembling 32-bitinstructions */
  34. #define OPCODE(INST) (INST & 0xfc000000)
  35.  
  36. #define RS(INST) (INST & 0x03e00000)
  37. #define FS(INST) (INST & 0x03e00000)
  38. #define BASE(INST) (INST & 0x03e00000)
  39.  
  40. #define RT(INST) (INST & 0x001f0000)
  41. #define FT(INST) (INST & 0x001f0000)
  42.  
  43. #define RD(INST) (INST & 0x0000f800)
  44. #define FD(INST) (INST & 0x0000f800)
  45.  
  46. #define SHAMT(INST) (INST & 0x000007c0)
  47. #define FORMAT(INST) (INST & 0x000007c0)
  48.  
  49. #define FUNCT(INST) (INST & 0x0000003f)
  50.  
  51. #define IMM(INST) (INST & 0x0000ffff)
  52. #define IOFFSET(INST) (INST & 0x0000ffff)
  53. #define COND(INST) (INST & 0x0000ffff)
  54.  
  55. #define TARGET(INST) (INST & 0x03ffffff)
  56.  
  57. /* Opcodes */
  58. #define R_TYPE_OP 0
  59. #define ADDIU_OP 9
  60. #define ANDI_OP 12
  61. #define ORI_OP 13
  62. #define LW_OP 35
  63. #define SW_OP 43
  64. #define LUI_OP 15
  65. #define BEQ_OP 4
  66. #define BNE_OP 5
  67. #define SLTI_OP 10
  68. #define SLTIU_OP 11
  69. #define J_OP 2
  70. #define JAL_OP 3
  71.  
  72.  
  73. /* Funct field values */
  74. #define ADDU_FUNCT 33
  75. #define SUBU_FUNCT 35
  76. #define AND_FUNCT 36
  77. #define OR_FUNCT 37
  78. #define SLL_FUNCT 0
  79. #define SRL_FUNCT 2
  80. #define SLT_FUNCT 42
  81. #define SLTU_FUNCT 43
  82. #define JR_FUNCT 8
  83.  
  84. #define SYSCALL_FUNCT 12
  85.  
  86.  
  87. /* Bottom of the text portion of memory: */
  88. /* where the program is stored. */
  89. #define TEXT_BOTTOM (0x00400000)
  90. #define DATA_BOTTOM (0x00401000)
  91. #define MEM_TOP (0x00404000)
  92.  
  93.  
  94. /* The computer is declared here */
  95. struct SimulatedComputer {
  96.  
  97. /* Program Counter */
  98. reg_word PC;
  99. /* General purpose registers: */
  100. reg_word R[32];
  101. /* Memory */
  102. reg_word Mem[(MEM_TOP - TEXT_BOTTOM)/BYTES_PER_WORD ];
  103.  
  104. };
Add Comment
Please, Sign In to add comment