C ++中的脚本汇编程序:我应该实现哪些操作? [英] Script Assembler in C++: What operations should I implement?
问题描述
我希望为脚本创建自己的汇编语言。现在它是
主要是为了娱乐和学习,但我也在创建
a游戏引擎,我想要这个系统。一旦汇编程序完成我将使用这个
汇编程序开发一个简单的脚本语言/编译器。您建议我在哪些运营商实施?
你的,
Morten Aune Lyrstad
I wish to create my own assembly language for script. For now it is
mostly for fun and for the sake of the learning, but I am also creating
a game engine where I want this system in. Once the assembler is done I
will develop a simple script language/compiler which uses this
assembler. What operators do you suggest I implement in it?
Yours,
Morten Aune Lyrstad
推荐答案
那应该是操作,而不是操作符。抱歉! :-)
That should be operations, not operators. Sorry! :-)
那应该是哪些操作,而不是什么操作员......对不起! ;-)
你的,
Morten Aune Lyrstad
That should be which operations, not what operators... Sorry! ;-)
Yours,
Morten Aune Lyrstad
Morten Aune Lyrstad写道:
Morten Aune Lyrstad wrote:
我希望为脚本创建自己的汇编语言。目前它主要是为了娱乐而且为了学习,但我也在创建一个游戏引擎,我想要这个系统。一旦汇编程序完成,我将会开发一个简单的脚本语言/编译器,它使用这个
汇编程序。您建议我在哪些运营商中实施?
I wish to create my own assembly language for script. For now it is
mostly for fun and for the sake of the learning, but I am also creating
a game engine where I want this system in. Once the assembler is done I
will develop a simple script language/compiler which uses this
assembler. What operators do you suggest I implement in it?
首先,您应该考虑什么类型的虚拟CPU'
想要实施。然后开始思考这个虚拟CPU应该支持哪些操作。
对于初学者:我推荐一个堆栈机器(即:没有寄存器,>
所有算术都可以通过从堆栈中推出来执行堆栈,执行
操作,将结果弹回到堆栈中。
所以很明显的操作是:
push
pop
cmp将堆栈顶部与堆栈(顶部+ 1)进行比较,测试是否相等
在堆栈上推送true(= 1)或false(= 0)
jump
jump_if_zero如果堆栈顶部等于0则有条件地跳转
load(从堆栈顶部指定的内存地址,将值推送到堆栈)
store(存储*顶部在内存地址指定的(顶部+ 1),从堆栈中弹出)< br $>
add
减法
乘以
除以
...
声明如
i = j + 2
将转换为
推< ; address_of_i>
push< address_of_j>
load
push 2
add
商店
一旦你有了它,如果你需要它们,你会想到其他的操作。
例如。你会遇到你经常产生的序列
....
推0
cmp
其中序列推0,cmp可以很容易地换成专用的
cmp_zero
或各种不同的跳转类型(jump_if_zero,jump_if_not零,jump_if_positive,
jump_if_negative等)
设计自己的CPU并弄清楚它有多好,这很有趣
编程。
-
Karl Heinz Buchegger
kb ****** @ gascad.at
这篇关于C ++中的脚本汇编程序:我应该实现哪些操作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!