⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 virtualmachine.cpp

📁 这是一个linux下的Shell.有命令历史和命令提示
💻 CPP
字号:
#include "VirtualMachine.h"VirtualMachine::VirtualMachine(){	pc_   = 0;	res_  = 0;	bp_   = 0;	sp_   = STACK_SIZE;	diverr = false;}VirtualMachine::~VirtualMachine(){}bool VirtualMachine::isAddrLegal(int index){	if(bp_ + index >= 0 && bp_ + index < STACK_SIZE)		return true;	return false;}bool VirtualMachine::add(int op1, int op2){	if(isAddrLegal(op1) && isAddrLegal(op2))	{		res_ =  stack[bp_+op1] + stack[bp_+op2];		return true;	}	return false;}bool VirtualMachine::sub(int op1, int op2){	if(isAddrLegal(op1) && isAddrLegal(op2))	{		res_ =  stack[bp_+op1] - stack[bp_+op2];		return true;	}	return false;}bool VirtualMachine::mul(int op1, int op2){	if(isAddrLegal(op1) && isAddrLegal(op2))	{		res_ =  stack[bp_ + op1] * stack[bp_ + op2];		return true;	}	return false;}bool VirtualMachine::div(int op1, int op2){	if(isAddrLegal(op1) && isAddrLegal(op2))	{		if(stack[bp_+op2])		{			res_ =  stack[bp_+op1] / stack[bp_+op2];			return true;		}		diverr = true;		return false;	}	diverr = false;	return false;}bool VirtualMachine::equal(int op1, int op2){	if(isAddrLegal(op1) && isAddrLegal(op2))	{		res_ = (stack[bp_ + op1] == stack[bp_ + op2]);		return true;	}	return false;}bool VirtualMachine::below(int op1, int op2){	if(isAddrLegal(op1) && isAddrLegal(op2))	{		res_ =  (stack[bp_ + op1] < stack[bp_ + op2]);		return true;	}	return false;}bool VirtualMachine::belowequal(int op1, int op2){	if(isAddrLegal(op1) && isAddrLegal(op2))	{		res_ =  (stack[bp_ + op1] <= stack[bp_ + op2]);		return true;	}	return false;}bool VirtualMachine::above(int op1, int op2){	if(isAddrLegal(op1) && isAddrLegal(op2))	{		res_ =  (stack[bp_ + op1] > stack[bp_ + op2]);		return true;	}	return false;}bool VirtualMachine::aboveequal(int op1, int op2){	if(isAddrLegal(op1) && isAddrLegal(op2))	{		res_ =  (stack[bp_ + op1] >= stack[bp_ + op2]);		return true;	}	return false;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -