Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

(SIC/XE) Suppose that you have a two-pass assembler that is written according to the algorithm in the figure below. In the case of a duplicate

(SIC/XE) Suppose that you have a two-pass assembler that is written according to the algorithm in the figure below.

image text in transcribed

image text in transcribed

In the case of a duplicate symbol, this assembler would give an error message only for the second (i.e., duplicate) definition. For example, it would give an error message only for line 5 of the program below. image text in transcribed

Suppose that you want to change the assembler to give error messages for all definitions of a doubly defined symbol (e.g., lines 4 and 5), and also for all references to a doubly defined symbol (e.g., lines 2 and 3). Describe the changes you would make to accomplish this. In making this modification, you should change the existing assembler as little as possible.

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 1f there is a symbol in the LABEL field then begin search SYMTAB for LABEL if found then set error flag (duplicate symbol) else insert (LABEL, LOCCTR) into SYMTAB end (if symbol) 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 add 3 * # 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 ingut line (from intermediate file) i OPCODE = START' then begin write listing line read next input line end (if START write Header record to object program initialize first Text record while OPCODE # END' do begin if this is not a conuent line then begin search OPTAB for OPCODE if found then begin if there is a symbol in OPERAND field then begin search SYMTAB for OPERAND 15 found then store symbol value as operand address else begin store 0 as operand address set error flag (undefined symbol) end end (if symbol) 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 initialize new Text record end add object code to Text record end fif 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) P3 1 2 START LDA 1000 ALPHA 3 STA ALPHA ALPHA RESW 1 ALPHA WORD 0 5 6 END

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions