Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* file: computer.h */
- /* Round V to next greatest B boundary */
- #define ROUND(V, B) (((int) V + (B-1)) & ~(B-1))
- /* Sign-extend a short to a long */
- #define SIGN_EX(X) ((X) & 0x8000 ? (X) | 0xffff0000 : (X))
- #define K 1024
- /* Type of a memory address. */
- typedef unsigned long mem_addr;
- /* Type of an instuction */
- typedef unsigned long instruction;
- #define BYTES_PER_WORD 4 /* On the MIPS processor */
- /* Type for a register */
- typedef long reg_word;
- /* Register names */
- #define REG_SP 29
- /* Macros for disassembling 32-bitinstructions */
- #define OPCODE(INST) (INST & 0xfc000000)
- #define RS(INST) (INST & 0x03e00000)
- #define FS(INST) (INST & 0x03e00000)
- #define BASE(INST) (INST & 0x03e00000)
- #define RT(INST) (INST & 0x001f0000)
- #define FT(INST) (INST & 0x001f0000)
- #define RD(INST) (INST & 0x0000f800)
- #define FD(INST) (INST & 0x0000f800)
- #define SHAMT(INST) (INST & 0x000007c0)
- #define FORMAT(INST) (INST & 0x000007c0)
- #define FUNCT(INST) (INST & 0x0000003f)
- #define IMM(INST) (INST & 0x0000ffff)
- #define IOFFSET(INST) (INST & 0x0000ffff)
- #define COND(INST) (INST & 0x0000ffff)
- #define TARGET(INST) (INST & 0x03ffffff)
- /* Opcodes */
- #define R_TYPE_OP 0
- #define ADDIU_OP 9
- #define ANDI_OP 12
- #define ORI_OP 13
- #define LW_OP 35
- #define SW_OP 43
- #define LUI_OP 15
- #define BEQ_OP 4
- #define BNE_OP 5
- #define SLTI_OP 10
- #define SLTIU_OP 11
- #define J_OP 2
- #define JAL_OP 3
- /* Funct field values */
- #define ADDU_FUNCT 33
- #define SUBU_FUNCT 35
- #define AND_FUNCT 36
- #define OR_FUNCT 37
- #define SLL_FUNCT 0
- #define SRL_FUNCT 2
- #define SLT_FUNCT 42
- #define SLTU_FUNCT 43
- #define JR_FUNCT 8
- #define SYSCALL_FUNCT 12
- /* Bottom of the text portion of memory: */
- /* where the program is stored. */
- #define TEXT_BOTTOM (0x00400000)
- #define DATA_BOTTOM (0x00401000)
- #define MEM_TOP (0x00404000)
- /* The computer is declared here */
- struct SimulatedComputer {
- /* Program Counter */
- reg_word PC;
- /* General purpose registers: */
- reg_word R[32];
- /* Memory */
- reg_word Mem[(MEM_TOP - TEXT_BOTTOM)/BYTES_PER_WORD ];
- };
Add Comment
Please, Sign In to add comment