Question: #fix the code from pass 1 import optab, sym inp = open ( Intermediatefile . txt , r ) out =

#fix the code
from pass1 import optab, sym
inp = open("Intermediatefile.txt","r")
out = open("Objectcodefile.txt","w")
symtab = open("Symboltab.txt","r")
l =[]
addrlist =[]
for i in inp.readlines():
ls = i.strip().split()
add = ls[0][2:]
if add !="-":
addrlist.append(add)
label = ls[1]
opcode = ls[2]
if len(ls)==4:
operand=ls[3]
if ls[1]=="START":
out.write("H^"+label+"^00"+start+"^00"+length[2:]+"
")
elif ls[2]=="END":
tempstr ="
E^00"+start
else:
if ls[2] in optab.keys():
op=optab[ls[2]]
if ls[2]=="RSUB":
op +="0000"
elif operand in sym.keys():
op += sym[operand][0:] #the 2 was 0
l.append(op)
elif ls[2]=='WORD':
op =hex(int(operand))
op1=str(op)
op1=op1[2:]
if len(op1)<6:
for i in range(6-len(op1)):
op1='0'+op1
l.append(op1)
elif ls[2]=='BYTE':
temp = operand[2:len(operand)-1]
arr = operand.split('\'')
if operand.find('X'):
l.append(temp)
elif operand.find('X'):
str = null
for i in temp:
hexcode = hex(ord(i))
tmp=str(hexcode)
str +=tmp[2:]
l.append(str)
elif arr[0]=="C":
chars = list(arr[1])
obline =''
for char in chars :
asciiCode = retAscii(char)
obline = obline +asciiCode
l.append(obline)
else:
l.append('-')
i =0
while i

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!