Answered step by step
Verified Expert Solution
Question
1 Approved Answer
#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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started