Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 21 additions & 6 deletions assembler.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
code=sys.stdin.read().splitlines()

# --------------------------------------------------------------------taking input from test case file -------------------------------------------------
# with open('test_case1.txt') as file1:
# with open('t.txt') as file1:
# code = file1.read().splitlines()
# ----------------------------------------------file to which the out generated will be written-----------------------------------------------------------

Expand Down Expand Up @@ -130,7 +130,7 @@ def f3(a, b):
f1()
return result

import numpy as np
# import numpy as np

def f4():
operaion3 = [[0,0,3],[0,5,6],[0,8,9]]
Expand Down Expand Up @@ -297,10 +297,11 @@ def f4():
f2()
f4()
f3(f1(),f2())
if (operation=='mov' and value[2][0] =='$'):
if (value[2] not in var and value[2] not in lab):
if (operation=='mov' and value[2][0] !='$'):
if (value[2] not in var and value[2] not in lab and value[2] not in flags):
error_message = f"error inncorrect immediate value enetred in line {c}"
print(f"error inncorrect immediate value enetred in line {c}")
error=True
file2.write(error_message)
file2.write("\n")

Expand All @@ -312,20 +313,23 @@ def f4():
if(value[2] not in var and value[2] not in lab):
error_message = f"error inncorrect immediate value enetred in line {c}"
print(f"error inncorrect immediate value enetred in line {c}")
error=True
file2.write(error_message)
file2.write("\n")

elif (case == "D" and value[2][0]!='$'):
if(value[2] not in var and value[2] not in lab):
error_message = f"error inncorrect immediate value enetred in line {c}"
print(f"error inncorrect immediate value enetred in line {c}")
error=True
file2.write(error_message)
file2.write("\n")

elif (case == "E" and value[1][0]!='$'):
if(value[1] not in var and value[1] not in lab):
error_message = f"error inncorrect immediate value enetred in line {c}"
print(f"error inncorrect immediate value enetred in line {c}")
error=True
file2.write(error_message)
file2.write("\n")

Expand Down Expand Up @@ -516,6 +520,7 @@ def f4():
#******************************************************************************************************************#

# checking for not using hlt missing and at end
h=False
c=0
f1()
f2()
Expand All @@ -532,6 +537,7 @@ def f4():
file2.write(error_message)
file2.write("\n")
error=True
h=True

except:
if ('hlt' not in main_lst[le-1]):
Expand All @@ -540,9 +546,10 @@ def f4():
file2.write(error_message)
file2.write("\n")
error=True
h=True

# nothing should be after halt
if ('hlt' not in main_lst[le-1]):
if ('hlt' not in main_lst[le-1] and h==False):
error_message = "cant execute lines after hlt"
print("cant execute lines after hlt")
file2.write(error_message)
Expand Down Expand Up @@ -655,6 +662,14 @@ def f4():
file2.write("\n")
print(s)

elif(operation=='mov' and value[2]=='FLAGS'):
a = value[1]
b = value[2]
s = operations['mov2'][0] + "00000" + RegAddress[a] + RegAddress[b]
file2.write(s)
file2.write("\n")
print(s)

elif operation in opr_sym:
# matching the values with op_mnemoics
case = operations[operation][1]
Expand Down Expand Up @@ -699,4 +714,4 @@ def f4():



# ***********************************************THE END*****************************************************
# ***********************************************THE END*****************************************************