|
論壇說明 |
歡迎您來到『史萊姆論壇』 ^___^ 您目前正以訪客的身份瀏覽本論壇,訪客所擁有的權限將受到限制,您可以瀏覽本論壇大部份的版區與文章,但您將無法參與任何討論或是使用私人訊息與其他會員交流。若您希望擁有完整的使用權限,請註冊成為我們的一份子,註冊的程序十分簡單、快速,而且最重要的是--註冊是完全免費的! 請點擊這裡:『註冊成為我們的一份子!』 |
|
主題工具 | 顯示模式 |
2007-04-09, 03:07 PM | #1 |
|
疑問 - 組譯SIC程式可能發生的錯誤
Pass1 和 Pass 2 演算法可以偵察某些組譯錯誤,不過可能發生的錯誤更多,列出組譯SIC程式可能生的錯誤。
每種錯誤會在何時偵測?如何偵測?組譯器應該採取什麼行動? 看的懂的大大幫幫我吧!! 我跟本看不懂= = 拜託 Pass 1: begin read first input line if OPCODE = 'START' then begin save #[OPERAND] as starting address initialize LOCCTR to starting address write line to intermediate file read next input line end {if START} else initialize LOCCTR to 0 while OPCODE ≠'END' do begin if this is not a comment line then begin if there is a symbo1 in the LABEL field then begin search SYMTAB for LABEL if found then set error flag(duplicate symbo1) else insert (LABEL,LOCCTR) into SYMTAB end {if symbo1} search OPTAB for OPCODE if found then add 3 {instruction length} to LOCCTR else if OPCODE = 'WORD' then add 3 to LOCCTR else if OPCODE = 'RESW' then add3 * #[OPERAND] to LOCCTR else if OPCODE = 'RESB' then add #[OPERAND] to LOCCTR else if OPCODE = 'BYTE' then begin find length of constant in bytes add length to LOCCTR end {if BYTE} else set error flag (invalid operation code) end {if not a comment} write line to intermediate file read next input line end {while not END} write last line to intermediate file save (LOCCTR - starting address) as program length end {Pass 1} Pass 2: begin read first input line {from intermediate file} if OPCODE = 'START' then begin write listing line read next input line end {if START} write Header record to object program initalize first Text record while OPCODE ≠'END' do begin if this is not a comment line then begin search OPTAB for OPCODE if found then begin if there is a symbo1 in OPERAND field then begin search SYMTAB for OPERAND if found then store symbo1 value as operand address else begin store 0 as operand address set error flag (undefined symbo1) end end {if symbo1} else store 0 as operand address assemble the object code instruction end {if opcode found} else if OPCODE = 'BYTE' or 'WORD' then convert constant to object code if object code will not fit into the current Text record then begin write Text record to object program initinlize new Text record end add object code to Text record end {if not comment} write listing line read next input line end {while not END} write last Text record to object program write End record to object program write last listing line end {Pass 2} |
送花文章: 0,
|
2007-04-09, 05:36 PM | #2 (permalink) |
註冊會員
|
symbol table 錯誤 (不會兩間房子的地址一樣吧)
op table 錯誤 指令格式不對等等 這個程式是 2 pass 組譯器 要將 source code 組譯成 object code 要經過兩的 pass 第一個 pass 主要是要 一行一行讀入 source code 加入 location count 輸出 intermediate file 第二個 pass 主要是要 組譯成 object code 輸出 object code 此帖於 2007-04-09 10:26 PM 被 snoopy 編輯. |
送花文章: 623,
|