Department of Computer Engineering: Rushikesh Nikam
Department of Computer Engineering: Rushikesh Nikam
Experiment No.1
Aim: Design and implementation of pass1 of two-pass assembler for general machine.
Problem Statement: Design and implementation of pass1 of two-pass assembler for general machine.
Program:
def pass1(source_code):
# Initialization
start_address = 0
optab = {
# Pass 1 logic
line = line.strip()
if not line or line.startswith(';'): # Skip comments or empty lines
continue
parts = line.split()
label = ""
label = ""
mnemonic = parts[0]
operand = ""
if label:
if label in symtab:
return None
symtab[label] = locctr
if mnemonic == "START":
start_address = int(operand)
locctr = start_address
intermediate_code.append((locctr, line))
continue
intermediate_code.append((locctr, line))
if mnemonic == "END":
break
if mnemonic == "WORD":
locctr += 3
locctr += 3 * int(operand)
locctr += int(operand)
if operand.startswith("C'") or operand.startswith("c'"):
locctr += len(operand[2:-1])
locctr += len(operand[2:-1]) // 2
locctr += optab[mnemonic]
else:
source_code = [
# Run Pass 1
print("Symbol Table:")
print("\nIntermediate Code:")
print(f"{address} : {code}")
print(f"\nStart Address: {start_address}")
Output: