c_cpp 旧的vm实现

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了c_cpp 旧的vm实现相关的知识,希望对你有一定的参考价值。

extern unsigned
cells_run_code(unsigned char* code)
{
	int jump_c;
	unsigned char* code_start = code;
	while(*code != CELLINS_X_STOP)
	{
		switch(*code++)
		{
			case CELLINS_X_STOP:
			   return 1;
			case CELLINS_X_INC_PTR:
			   assert((++CELL_PTR) != CELL_END);
			   break;
			case CELLINS_X_DEC_PTR:
			   assert((CELL_PTR--) != CELL_BEGIN);
			   break;
			case CELLINS_X_PUT_IN:
			   CELL_PTR->_in = *(int*)(code);
			   code += sizeof(int);
			   break;
			case CELLINS_X_PUT_OUT:
			   CELL_PTR->_out = *(int*)(code);
			   code += sizeof(int);
			   break;
			case CELLINS_X_PUT_OP:
			   CELL_PTR->_op = *(int*)(code);
			   code += sizeof(int);
			   break;
			case CELLINS_X_PRINT_IN:
			   printf("%d\n", CELL_PTR->_in);
			   break;
			case CELLINS_X_PRINT_OUT:
			   printf("%d\n", CELL_PTR->_out);
			case CELLINS_X_PUSH_BACK:
			   assert(CELL_PTR != CELL_BEGIN);
			   (CELL_PTR - 1)->_in = CELL_PTR->_out;
			   break;
			case CELLINS_X_PUSH_NEXT:
			   assert((CELL_PTR + 1) != CELL_END);
			   (CELL_PTR + 1)->_in = CELL_PTR->_out;
			   break;
			case CELLINS_X_CALL_OP:
			   // not currently used.
			   break;
			case CELLINS_X_END_OP:
			   // not currently used.
			   break;
			case CELLINS_X_SUB:
			   CELL_COPY_IN_OUT(CELL_PTR);
			   CELL_PTR->_out -= *(int*)(code);
			   code += sizeof(int);
			   break;
			case CELLINS_X_PLUS:
			   CELL_COPY_IN_OUT(CELL_PTR);
			   CELL_PTR->_out += *(int*)(code);
			   code += sizeof(int);
			   break;
			case CELLINS_X_JUMP:
			   jump_c = (*(int*)(code));
			   code = code_start + jump_c;
			   break;
			default:
			   fprintf(stderr, "cells_run_code ERROR: Unkown instruction code byte %u\n", *code);
			   cells_core_dump(50);
			   exit(2);
		}
	}
	return code - code_start;
}

int main(int argc, char const *argv[])
{
	cells_clean();
	cells_core_dump(10);
	return 0;
}

以上是关于c_cpp 旧的vm实现的主要内容,如果未能解决你的问题,请参考以下文章

删除 VM 后从 Azure 中删除磁盘

Oracle VM VirtualBox找不到模块

c_cpp ObServer实现

c_cpp 28.实现strStr()

c_cpp 使用数组实现堆栈

c_cpp 通用QRunnable实现