-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstruction.py
102 lines (82 loc) · 1.89 KB
/
instruction.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import re
# ins will have all the instructions
# each member is a separate instruction
ins = []
while True:
line = input()
if line:
ins.append(line)
else:
break
#print(ins)
#for i in ins:
# for j in i.split(" "):
# if(j=="ADD"):
# print("YES")
# else:
# print("NO")
"""
Instruction: BIC r0, r1, r2, LSL #1 => BIC is Add with complement
Initial value::
r1 = 0b1111
r2 = 0b0101
What will be the content of register r0?
"""
# ========================================================================>
"""
Functions for logical operation
"""
def comp(x):
x_ = ""
for i in range(len(x)):
if x[i] == '1':
x_ += '0'
elif x[i] == '0':
x_ += '1'
return x_
def logicalOr(x, y):
# x = 01010011
# y = 11011001
x_ = ""
for i in range(len(x)):
if x[i]=='0' and y[i] == '0':
x_ += '0'
else:
x_ += '1'
return x_
def logicalAnd(x, y):
x_ = ""
for i in range(len(x)):
if x[i]=='1' and y[i] == '1':
x_ += '1'
else:
x_ += '0'
return x_
def logicalXor(x, y):
x_ = ""
for i in range(len(x)):
if (x[i]=='0' and y[i] == '0') or (x[i]=='1' and y[i]=='1'):
x_ += '0'
else:
x_ += '1'
return x_
# ========================================================================>
def BIC(op, in1, in2):
not_in2 = comp(in2)
res = logicalAnd(in1, not_in2)
print(res)
r1 = input("Enter the value for r1: ")
r2 = input("Enter the value for r2: ")
r0 = ""
#for i in ins:
# j = i.split(" ")
# if j[0]=="BIC":
# BIC(r0, r1, r2)
# else:
# print("Option not available")
for i in ins:
inst_list = re.split(" |, |\(|\)", i)
if inst_list[0] == "BIC":
BIC(r0, r1, r2)
else:
print("Option not available")