Skip to content

Commit 10bf853

Browse files
committed
Update files
0 parents  commit 10bf853

File tree

9 files changed

+641
-0
lines changed

9 files changed

+641
-0
lines changed

OCG.py

Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
"""
4+
Created on Fri Oct 4 15:18:09 2019
5+
6+
@author: ashish
7+
"""
8+
import tkinter as tk
9+
import SIC as s
10+
import XE as x
11+
12+
output = '' #sic global variables
13+
op=""
14+
operand=""
15+
address=""
16+
17+
output1 = '' #sic_xe global variables
18+
op1=""
19+
operand1=""
20+
address1=""
21+
pc=""
22+
b=""
23+
24+
25+
def clear_sic():
26+
global op
27+
global operand
28+
global address
29+
global output
30+
op.delete(0,tk.END)
31+
operand.delete(0,tk.END)
32+
address.delete(0,tk.END)
33+
output.config(text="Enter the Inputs")
34+
35+
36+
def clear_sicxe():
37+
global op1
38+
global operand1
39+
global address1
40+
global pc
41+
global b
42+
global output1
43+
op1.delete(0,tk.END)
44+
operand1.delete(0,tk.END)
45+
address1.delete(0,tk.END)
46+
pc.delete(0,tk.END)
47+
b.delete(0,tk.END)
48+
output1.config(text="Enter the Inputs")
49+
50+
def sic():
51+
sub = tk.Tk() #create window
52+
sub.title("SIC")
53+
L1 = tk.Label(sub, text = "Mnemonic opcode",font=("Bitstream Charter",15," bold"))
54+
L1.place(x=254,y=270 )
55+
global op
56+
op=tk.Entry(sub,font=("Bitstream Charter",14," bold"),width=15)
57+
op.place(x=256,y=300)
58+
L2 = tk.Label(sub, text = "Operand",font=("Bitstream Charter",15," bold"))
59+
L2.place(x=595,y=270 )
60+
global operand
61+
operand=tk.Entry(sub,font=("Bitstream Charter",14," bold"),width=15)
62+
operand.place(x=553,y=300)
63+
L3= tk.Label(sub, text = "Operand Address",font=("Bitstream Charter",15," bold"))
64+
L3.place(x=859,y=270 )
65+
global address
66+
address=tk.Entry(sub,font=("Bitstream Charter",14," bold"),width=15)
67+
address.place(x=857,y=300)
68+
button1 = tk.Button(sub,text='GENERATE',bg="green",fg="white",font=("Courier 10 Pitch",17,"bold ")\
69+
,width=10,height=1,border=2,relief="raised",command=update_answer_sic)
70+
button1.place(x=550,y=400)
71+
button2 = tk.Button(sub,text='CLEAR',bg="red",fg="white",font=("Courier 10 Pitch",17,"bold ")\
72+
,width=10,height=1,border=2,relief="raised",command=lambda :clear_sic())
73+
button2.place(x=550,y=450)
74+
L4= tk.Label(sub, text = "NOTE: Enter empty field with '-'",font=("Bitstream Charter",15,"bold italic"),fg="red")
75+
L4.place(x=500,y=350 )
76+
global output
77+
output=tk.Label(sub,text="Enter the Inputs",width=38,font=("Courier 10 Pitch",25,"bold italic"),bg="black",fg="green")
78+
output.place(x=260,y=140)
79+
sub.mainloop()
80+
81+
def update_answer_sic():
82+
global op
83+
global operand
84+
global address
85+
result=s.call1(op.get(),operand.get(),address.get())
86+
global output
87+
output.config(text='{}'.format(result))
88+
89+
def sicxe():
90+
sub1 = tk.Tk() #create window
91+
sub1.title("SIC/XE")
92+
L1 = tk.Label(sub1, text = "Mnemonic opcode",font=("Bitstream Charter",15," bold"))
93+
L1.place(x=45,y=270 )
94+
global op1
95+
op1=tk.Entry(sub1,font=("Bitstream Charter",14," bold"),width=15)
96+
op1.place(x=50,y=300)
97+
L2 = tk.Label(sub1, text = "Operand",font=("Bitstream Charter",15," bold"))
98+
L2.place(x=345,y=270 )
99+
global operand1
100+
operand1=tk.Entry(sub1,font=("Bitstream Charter",14," bold"),width=15)
101+
operand1.place(x=305,y=300)
102+
L3 = tk.Label(sub1, text = "Operand Address",font=("Bitstream Charter",15," bold"))
103+
L3.place(x=550,y=270 )
104+
global address1
105+
address1=tk.Entry(sub1,font=("Bitstream Charter",14," bold"),width=15)
106+
address1.place(x=550,y=300)
107+
L4= tk.Label(sub1, text ="PC address" ,font=("Bitstream Charter",15," bold"))
108+
L4.place(x=850,y=270 )
109+
global pc
110+
pc=tk.Entry(sub1,font=("Bitstream Charter",14," bold"),width=15)
111+
pc.place(x=825,y=300)
112+
L5= tk.Label(sub1, text ="Base address" ,font=("Bitstream Charter",15," bold"))
113+
L5.place(x=1105,y=270 )
114+
global b
115+
b=tk.Entry(sub1,font=("Bitstream Charter",14," bold"),width=15)
116+
b.place(x=1080,y=300)
117+
button1 = tk.Button(sub1,text='GENERATE',bg="green",fg="white",font=("Courier 10 Pitch",17,"bold "),\
118+
width=10,height=1,border=2,relief="raised",command=update_answer_xe)
119+
button1.place(x=550,y=400)
120+
button2 = tk.Button(sub1,text='CLEAR',bg="red",fg="white",font=("Courier 10 Pitch",17,"bold ")\
121+
,width=10,height=1,border=2,relief="raised",command=lambda :clear_sicxe())
122+
button2.place(x=550,y=450)
123+
L6= tk.Label(sub1, text = "NOTE: Enter empty field with '-'",font=("Bitstream Charter",15,"bold italic"),fg="red")
124+
L6.place(x=500,y=350 )
125+
global output1
126+
output1=tk.Label(sub1,text="Enter the Inputs",width=39,font=("Courier 10 Pitch",25,"bold italic"),bg="black",fg="green")
127+
output1.place(x=260,y=140)
128+
sub1.mainloop()
129+
130+
def update_answer_xe():
131+
global op1
132+
global operand1
133+
global address1
134+
global pc
135+
global b
136+
result=x.call2(op1.get(),operand1.get(),address1.get(),pc.get(),b.get())
137+
global output1
138+
output1.config(text='{}'.format(result))
139+
140+
141+
if __name__== "__main__" :
142+
root = tk.Tk() #create window
143+
root.title("OCG") #title
144+
background = tk.PhotoImage(file="background.png")
145+
w1 = tk.Label(root, image=background) #background image
146+
w1.place(x=0,y=0,relwidth=1,relheight=1)
147+
logo= tk.PhotoImage(file="designer.png")
148+
w2 = tk.Label(root, image=logo,bg="white",anchor='nw',fg="black",text="OBJECT CODE GENERATOR",compound = "left",font=("Courier 10 Pitch",35,"bold italic"),padx=10,pady=5).pack(fill="both")
149+
button_image= tk.PhotoImage(file="binary-code.png")
150+
button1 = tk.Button(root,image=button_image,text='SIC',width=200,height=200,bg="white",font=("Courier 10 Pitch",25,"bold "),compound="left",border=20,relief="groove",command=lambda :sic())
151+
button1.place(x=270,y=250)
152+
button2 = tk.Button(root,image=button_image,text='SIC/XE',width=200,height=200,bg="white",font=("Courier 10 Pitch",25,"bold"),compound="left",border=20,relief="groove",command=lambda :sicxe())
153+
button2.place(x=720,y=250)
154+
student=tk.PhotoImage(file="man.png")
155+
w4=tk.Label(root,text="Ashish M J\n4NI17IS017",image=student,font=("Bitstream Charter",15,"italic bold"),bg="white",compound="left",padx=10,pady=5,anchor="s",width=770)
156+
w4.place(x=250,y=650)
157+
root.mainloop()
158+
159+

SIC.py

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
"""
4+
Created on Tue Aug 20 23:31:38 2019
5+
6+
@author: ashish
7+
"""
8+
def binary_convert(num): #binary_conversion
9+
s=f'{num:04b}'
10+
return s
11+
12+
13+
def obj_code(op,label,add):
14+
count=0
15+
num=opcode[op] #opcode(1-8)
16+
oc=binary_convert(int(num[0],16))+binary_convert(int(num[1],16))
17+
for i in range(len(label)): #index_bit(9)
18+
if label[i]==',':
19+
if label[i+1]=="X":
20+
count=1
21+
break
22+
if count==0:
23+
oc=oc+'0'
24+
else:
25+
oc=oc+'1'
26+
n=binary_convert(int(add[0],16)) #address(10-24)
27+
n=n[1:]
28+
oc=oc+n
29+
oc=oc+binary_convert(int(add[1],16))
30+
oc=oc+binary_convert(int(add[2],16))
31+
oc=oc+binary_convert(int(add[3],16)) #binary_format to hexa
32+
s1=oc[:4] #if wanted tocaps
33+
s1=hex(int(s1,2))
34+
s1=s1.upper()
35+
s2=oc[4:8]
36+
s2=hex(int(s2,2))
37+
s2=s2.upper()
38+
s3=oc[8:12]
39+
s3=hex(int(s3,2))
40+
s3=s3.upper()
41+
s4=oc[12:16]
42+
s4=hex(int(s4,2))
43+
s4=s4.upper()
44+
s5=oc[16:20]
45+
s5=hex(int(s5,2))
46+
s5=s5.upper()
47+
s6=oc[20:]
48+
s6=hex(int(s6,2))
49+
s6=s6.upper()
50+
s=s1[2:]+s2[2:]+s3[2:]+s4[2:]+s5[2:]+s6[2:]
51+
return s
52+
######################################################################
53+
opcode={'STL':'14','JSUB':'48','LDA':'00','COMP':'28','STCH':'54','LDCH':'50',\
54+
"RSUB":"4C","JEQ":"30","J":"3C","STA":"0C","LDL":"08","LDX":"04","TD":"E0",\
55+
"RD":"D8","TIX":"2C","JLT":"38","STX":"10","WD":"DC",}
56+
57+
def call1(op,label,address):
58+
op=op.upper()
59+
label=label.upper()
60+
address=address.upper()
61+
if (op=="BYTE" or op=="WORD") and address=="-": #Word or byte instruction
62+
if label[0]=="X": #BYTE X'F1'
63+
for i in range(len(label)):
64+
if label[i]=="'":
65+
return label[i+1:len(label)-1]
66+
elif label=="C'EOF'": #EOF instruction
67+
return "454F46"
68+
else: #WORD 3 example
69+
label=hex(int(label))
70+
return label[2:].upper()
71+
elif label=="-" and address=="-": #RSUB - -
72+
c=opcode[op]+"0000"
73+
return c
74+
75+
else:
76+
try:
77+
a=obj_code(op,label,address)
78+
return a
79+
except KeyError: #RESW or RESB or START
80+
return "No Object code for such instruction"
81+
except:
82+
return "INVALID INPUT"
83+
84+

0 commit comments

Comments
 (0)