Question: #fix the code from pass 1 import optab, sym inp = open ( Intermediatefile . txt , r ) out =
#fix the code
from pass import optab, sym
inp openIntermediatefiletxtr
out openObjectcodefiletxtw
symtab openSymboltabtxtr
l
addrlist
for i in inp.readlines:
ls istripsplit
add ls:
if add :
addrlist.appendadd
label ls
opcode ls
if lenls:
operandls
if ls"START":
out.writeHlabelstartlength:
elif ls"END":
tempstr
Estart
else:
if ls in optab.keys:
opoptabls
if ls"RSUB":
op
elif operand in symkeys:
op symoperand: #the was
lappendop
elif ls'WORD':
op hexintoperand
opstrop
opop:
if lenop:
for i in rangelenop:
opop
lappendop
elif ls'BYTE':
temp operand:lenoperand
arr operand.split
if operand.findX:
lappendtemp
elif operand.findX:
str null
for i in temp:
hexcode hexordi
tmpstrhexcode
str tmp:
lappendstr
elif arrC:
chars listarr
obline
for char in chars :
asciiCode retAsciichar
obline obline asciiCode
lappendobline
else:
lappend
i
while i
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
