Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
12 views2 pages

Pass 1

The document contains a Python script that processes macro definitions in assembly language. It defines macros, their parameters, and generates a Macro Definition Table (MDT), Macro Name Table (MNT), and Argument List Array (ALA). The script prints these tables after parsing the defined macros from a hardcoded string input.

Uploaded by

Prem Dubay 3229
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views2 pages

Pass 1

The document contains a Python script that processes macro definitions in assembly language. It defines macros, their parameters, and generates a Macro Definition Table (MDT), Macro Name Table (MNT), and Argument List Array (ALA). The script prints these tables after parsing the defined macros from a hardcoded string input.

Uploaded by

Prem Dubay 3229
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

def main():

# <<< Instead of reading from file, define input here >>>


program = """MACRO
NEERAJ1 &FIRST,&SECOND
B &FIRST
H &SECOND
MEND
MACRO
NEERAJ2 &ARG1,&ARG2
N &ARG1
OH &ARG2
MEND
START
NEERAJ1 DATA9
NEERAJ2 DATA5
END"""

lines = program.strip().splitlines()

mdt, mnt, ala = [], [], []


mnt_index, ala_indices = [], []
alas = []

i = 0
while i < len(lines):
line = lines[i].strip()
words = line.split()

if line == "END":
break

if words[0] == "MACRO":
i += 1
line = lines[i].strip()
words = line.split()

macro_name = words[0]
params = words[1].split(",") if len(words) > 1 else []

mnt.append([macro_name, len(mdt)])
alas.append([len(ala), len(mnt_index)])

# Add parameters to ALA


for p in params:
ala.append(p)
ala_indices.append(len(ala_indices))

mdt.append(f"{macro_name} {','.join(params)}")
i += 1

while not lines[i].strip().startswith("MEND"):


l = lines[i].strip()
for idx in range(alas[-1][0], alas[-1][0] + len(params)):
l = l.replace(ala[idx], f"#{ala_indices[idx]}")
mdt.append(l)
i += 1
mdt.append(lines[i].strip()) # Add MEND

i += 1
print("==== PASS 1 ====\n")

print("ALA:")
for idx in range(0, len(ala), 2):
group = ala[idx:idx+2]
print(f"[{', '.join(group)}]")

print("\nMNT:")
for idx, entry in enumerate(mnt):
print(f"[{entry[0]}, {entry[1]}]")

print("\nMDT:")
for line in mdt:
print(line)

if __name__ == "__main__":
main()

You might also like