史萊姆論壇

返回   史萊姆論壇 > 專業主討論區 > 程式語言討論區
忘記密碼?
論壇說明

歡迎您來到『史萊姆論壇』 ^___^

您目前正以訪客的身份瀏覽本論壇,訪客所擁有的權限將受到限制,您可以瀏覽本論壇大部份的版區與文章,但您將無法參與任何討論或是使用私人訊息與其他會員交流。若您希望擁有完整的使用權限,請註冊成為我們的一份子,註冊的程序十分簡單、快速,而且最重要的是--註冊是完全免費的!

請點擊這裡:『註冊成為我們的一份子!』

Google 提供的廣告


發文 回覆
 
主題工具 顯示模式
舊 2007-04-09, 03:07 PM   #1
拓斗
榮譽勳章

勳章總數
UID -
在線等級:
文章: n/a
精華:
預設 疑問 - 組譯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, 收花文章: 0 篇, 收花: 0 次
回覆時引用此帖
舊 2007-04-09, 05:36 PM   #2 (permalink)
註冊會員
 
snoopy 的頭像
榮譽勳章
UID - 33737
在線等級: 級別:49 | 在線時長:2676小時 | 升級還需:24小時級別:49 | 在線時長:2676小時 | 升級還需:24小時級別:49 | 在線時長:2676小時 | 升級還需:24小時級別:49 | 在線時長:2676小時 | 升級還需:24小時
註冊日期: 2003-02-02
VIP期限: 2011-06
住址: 台南共和國
文章: 1831
精華: 0
現金: 12744 金幣
資產: 12834 金幣
預設

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 編輯.
snoopy 目前離線  
送花文章: 623, 收花文章: 392 篇, 收花: 1288 次
回覆時引用此帖
發文 回覆



發表規則
不可以發文
不可以回覆主題
不可以上傳附加檔案
不可以編輯您的文章

論壇啟用 BB 語法
論壇啟用 表情符號
論壇啟用 [IMG] 語法
論壇禁用 HTML 語法
Trackbacks are 禁用
Pingbacks are 禁用
Refbacks are 禁用


所有時間均為台北時間。現在的時間是 06:15 AM


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


SEO by vBSEO 3.6.1