Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

#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

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

Recommended Textbook for

Transact SQL Cookbook Help For Database Programmers

Authors: Ales Spetic, Jonathan Gennick

1st Edition

1565927567, 978-1565927568

More Books

Students also viewed these Databases questions

Question

What are the Five Phases of SDLC? Explain each briefly.

Answered: 1 week ago

Question

How can Change Control Procedures manage Project Creep?

Answered: 1 week ago