在大學的最後一個學期,我的計算機語言課的老師教給我們一個深奧的語言Whitespace。爲了以非常繁忙的時間表(midterms)更好地學習語言,我在Python中寫了interpreter和assembler。一個assembly language被設計爲便於編寫程序,並且sample program是用給定程序集mnemonics編寫的。你對這些彙編助記符有什麼建議嗎?
現在是夏天,一個新的項目已經開始,目標是重寫Whitespace 0.3的解釋器和彙編器,隨後會有進一步的發展。由於在設計過程中需要比以前多得多的時間,因此您將在這裏給出一個提供彙編語言修訂後的助記符集的大綱。這篇文章被標記爲wiki供他們討論。
過去你有過使用匯編語言的經驗嗎?有沒有一些你認爲應該改名爲不同的指令?你是否發現自己在盒子外面思考,並採用與助記符命名不同的範式?如果您對這些問題中的任何一個都能回答「是」,那麼您非常歡迎您。主觀答案表示讚賞!
棧操作(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:[索引] [空間])
算術命令等的堆棧頂部的兩個項目進行操作,並且與操作的結果替換它們。推送的第一個項目被認爲是操作員的剩餘部分。
add Addition
sub Subtraction
mul Multiplication
div Integer Division
mod Modulo
堆存取(IMP:[索引] [Tab]鍵)
堆訪問命令看堆棧找到物品的地址被存儲或檢索。要存儲項目,請按地址,然後按值並運行存儲命令。要檢索一個項目,請按住該地址並運行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
問:你將如何重新設計,重寫或重命名之前的助記符是爲了什麼原因?
聖潔的廢話,一個空白的彙編?我相信你的極客米就上升到了十一點! – Martin 2010-05-25 00:43:22