查看單個文章
舊 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 次
回覆時引用此帖