virtualmachine.cpp

来自「这是一个linux下的Shell.有命令历史和命令提示」· C++ 代码 · 共 116 行

CPP
116
字号
#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 + =
减小字号Ctrl + -
显示快捷键?