📄 cpu.h
字号:
/*
* CPU.h
* this file define the class CPU
*/
#pragma once
#include "all.h"
#include <memory>
using namespace std;
extern int mem[MEM_SIZE];
class CPU
{
friend class VM;
public:
CPU();
/***********************************************
* public interface
*/
public:
//clear all the registers
void Reset();
//fetch instruction into the instruction registers from memory
void FetchIns();
//process current instruction
//which is stored in the instruction registers
void DoOperation();
/***********************************************
* handle the operations
*/
private:
void Handle_LOAD(int r,int m);
void Handle_STOR(int m,int r);
void Handle_MOV(int r1,int r2);
void Handle_ADD(int r1,int r2);
void Handle_SUB(int r1,int r2);
void Handle_MPY(int r1,int r2);
void Handle_DIV(int r1,int r2);
void Handle_INC(int r);
void Handle_DEC(int r);
void Handle_JMP(int m);
void Handle_JPZ(int m,int r);
void Handle_OPEN(int IO);
void Handle_CLOSE(int IO);
void Handle_IN(int r);
void Handle_OUT(int r);
void Handle_HALT();
/***********************************************
* assert the register ID or memory
* adderss is valid
*/
private:
void Assert_REG(int r);
void Assert_DataADRS(int address);
void Assert_InsADRS(int address);
private:
int GetDirAddress(int address);
/***********************************************
* all the registers
*/
private:
//common registers
int R[24];
//program counter registers
int PC;
//instruction register
int IR[3];
//this register records the the head address of the process
int PAR;
//this register records the length of the process instruction section
int PILR;
//this register records the length of the process data section
int PDLR;
};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -