Skip to content

Works #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
4 changes: 3 additions & 1 deletion README
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
simple assembbler python
This is a simple assembler written in Python by akigandhi

Just forked it and made a few minor changes
118 changes: 118 additions & 0 deletions assembler.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
import re
def main():
f = open('tp.txt','r')
a = open('mnemtab.txt','r')
r = open('symtab.txt','w')
l = open('littab.txt','w')
o = open('out.txt','w')
start = f.read().split()
counter = int(start[1])-1
foo = 0
for index,i in enumerate( start):
o.write('\n'+str(counter)+' + ')
counter+=1
b = i.split()
for c in b:
if c == 'START':

break
elif c == 'STOP':

o.write('00 0 000')
f.close()
a.close()
# r.close()
l.close()
# o.close()
handle(o,r,counter,index+1)

nhandle(o,r)
print('DONE!')
foo+=1
break

if c == 'AREG':
o.write('1 ')
continue

elif c == 'BREG':
o.write('2 ')
continue
elif c == 'CREG':
o.write('3 ')
continue
elif c == 'DREG':
o.write('4 ')
continue
co = 0
for line in a:

word = line.split()
for lt,eword in enumerate(word):
if c == eword:
o.write(str(word[lt+1])+' ')
co+=1
break
if co == 1:
break

if co == 0:

o.write(c+' ')

if foo > 0:
break





def handle(p,s,conter,ind):
g = open('tp.txt','r')
# s = open('symtab.txt','w')
# p = open('out.txt','w')
for inde,lis in enumerate(g):
if inde > ind:
p.write('\n'+str(conter)+' + ')


sp = lis.split()
for cou,ew in enumerate(sp):
if ((sp[cou+1]!=''and sp[cou+1] == 'DS')or (sp[cou+1]!=''and sp[cou+1] == 'DC')):
s.write(ew+' '+str(conter))
elif ew == 'DC':
p.write('00 0 00'+sp[cou+1])
break
conter+=1
g.close()
# s.close()
# p.close()

def nhandle(my,by):
my.close()
by.close()
my = open('out.txt','r+')
by = open('symtab.txt','r+')
for ata in my:
aba = ata.split()
for eaw in aba:
for bata in by:
ara = bata.split()
for ist,ewo in enumerate(ara):
if eaw == ewo:
my.write(re.sub(eaw,str(ara[ist+1]),ata))
break
break
break










if __name__ == "__main__":main()

106 changes: 0 additions & 106 deletions assembler.txt

This file was deleted.

File renamed without changes.
119 changes: 0 additions & 119 deletions new.txt

This file was deleted.