史萊姆論壇

史萊姆論壇 (http://forum.slime.com.tw/)
-   程式語言討論區 (http://forum.slime.com.tw/f76.html)
-   -   組譯SIC程式可能發生的錯誤 (http://forum.slime.com.tw/thread202387.html)

拓斗 2007-04-09 03:07 PM

組譯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}

snoopy 2007-04-09 05:36 PM

symbol table 錯誤 (不會兩間房子的地址一樣吧)
op table 錯誤
指令格式不對等等

這個程式是 2 pass 組譯器
要將 source code 組譯成 object code
要經過兩的 pass

第一個 pass 主要是要
一行一行讀入 source code
加入 location count
輸出 intermediate file

第二個 pass 主要是要
組譯成 object code
輸出 object code


所有時間均為台北時間。現在的時間是 07:15 PM

Powered by vBulletin® 版本 3.6.8
版權所有 ©2000 - 2024, Jelsoft Enterprises Ltd.

『服務條款』

* 有問題不知道該怎麼解決嗎?請聯絡本站的系統管理員 *


SEO by vBSEO 3.6.1