编程语言
首页 > 编程语言> > python – 你对这些汇编助记符有什么建议吗?

python – 你对这些汇编助记符有什么建议吗?

作者:互联网

上学期大学时,我的计算机语言课程的老师教给我们一个名为Whitespace的深奥语言.为了更好地学习语言,我的课程非常繁忙(midterms),我在Python写了一个interpreterassembler.7004被设计了为了方便编写程序,使用给定的程序集mnemonics编写了sample program.

现在是夏天,一个新的项目已经开始,其目标是重写Whitespace 0.3的翻译和汇编程序,之后会有进一步的发展.由于有很多额外的时间来处理它的设计,因此这里给出的是一个大纲,它为汇编语言提供了一套修订的助记符.这篇文章被标记为维基进行讨论.

你曾经有过汇编语言的经验吗?是否有一些您认为应该重命名为不同的指令?您是否发现自己在盒子外面思考并使用与助记符命名不同的范例?如果您对这些问题的回答都是肯定的,那么欢迎您.主观答案非常感谢!

堆栈操作(IMP:[空格])

堆栈操作是更常见的操作之一,因此IMP [空间]的短缺.有四个堆栈指令.

hold N       Push the number onto the stack
copy         Duplicate the top item on the stack
copy N       Copy the nth item on the stack (given by the argument) onto the top of the stack
swap         Swap the top two items on the stack
drop         Discard the top item on the stack
drop N       Slide n items off the stack, keeping the top item

算术(IMP:[Tab] [Space])

算术命令对堆栈中的前两项进行操作,并将其替换为操作结果.推送的第一个项目被认为是运算符的左侧.

add          Addition
sub          Subtraction
mul          Multiplication
div          Integer Division
mod          Modulo

堆访问(IMP:[Tab] [Tab])

堆访问命令查看堆栈以查找要存储或检索的项的地址.要存储项目,请按地址然后按值并运行store命令.要检索项目,请按地址并运行retrieve命令,该命令将存储在堆栈顶部位置的值.

save         Store
load         Retrieve

流量控制(IMP:[LF])

流量控制操作也很常见.子程序由标签标记,以及条件和无条件跳转的目标,通过它们可以实现循环.程序必须通过[LF] [LF] [LF]结束,以便解释器可以干净地退出.

L:           Mark a location in the program
call L       Call a subroutine
goto L       Jump unconditionally to a label
if=0 L       Jump to a label if the top of the stack is zero
if<0 L       Jump to a label if the top of the stack is negative
return       End a subroutine and transfer control back to the caller
halt         End the program

I / O(IMP:[Tab] [LF])

最后,我们需要能够与用户进行交互.有用于读取和写入数字和单个字符的IO指令.有了这些,就可以编写字符串操作例程.读取指令采用堆栈地址来存储堆栈顶部的结果.

print chr    Output the character at the top of the stack
print int    Output the number at the top of the stack
input chr    Read a character and place it in the location given by the top of the stack
input int    Read a number and place it in the location given by the top of the stack

问题:您将如何重新设计,重写或重命名以前的助记符以及原因?

最佳答案:

>按#n,表明n是立即数.
>“交换”有时是“exc”或“exch”我认为.
>“保存”通常是“st”(商店)
>“加载”通常是“ld”
>“call”也可以是“jsr”或“bl”.
>“goto”通常是“jmp”或“bra”
>“if = 0”通常是“beq”
>“如果< 0”通常是“blt”
>“返回”通常是“ret”或“blr”
>“退出”通常在CPU的上下文中“停止”/“hlt”.
>“print chr”和“print int”可以是“print.c”和“print.i”.有许多方法可以指定指令变体,但通常它不在操作数中.

编辑:

如果您不介意混淆操作码和寻址模式,请使用CISCy语法,

>“推(sp)”而不是“复制”
>“推N(sp)”而不是“复制N”(模数乘以字长)
>“push *(sp)”而不是“load”(除了它在按下加载的值之前弹出)
>“pop * 1(sp)”而不是“push”(除了它实际弹出两次)

另一方面,基于堆栈的代码通常将push和pop视为隐式.在那种情况下,“imm n”(立即)而不是“推”.然后所有堆栈操作都是纯粹的堆栈操作,这很好且一致.

我不确定我怎么写“drop N” – 这个描述听起来像“drop 1”并不等同于“drop”这看起来很奇怪.

标签:python,assembly,whitespace,mnemonics,esoteric-languages
来源: https://codeday.me/bug/20190515/1110979.html