-
Notifications
You must be signed in to change notification settings - Fork 1
/
as504.py
36 lines (27 loc) · 958 Bytes
/
as504.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
#!/usr/bin/python
from optparse import OptionParser
import os
import subprocess
import sys
usage = 'usage: %prog INPUT'
description = 'Assembles 8051 assembly instructions in INPUT to a .hex file.'
parser = OptionParser(usage=usage, description=description)
options, args = parser.parse_args()
if len(args) != 1:
parser.error('1 argument expected, got %d' % len(args))
filename = args[0]
if filename[-4:] == '.asm':
filename = filename[:-4]
if not os.path.exists(filename + '.asm'):
parser.error("'%s.asm' is not a file." % filename)
process = subprocess.Popen(['as504.exe', '-l', filename + '.asm'], stdin=subprocess.PIPE)
# continue past the 'Press enter' prompt
process.communicate('\r\n')
process.wait()
if process.returncode != 0:
sys.exit(1)
with open(filename + '.hex') as hexfile:
hex = hexfile.read()
hex = hex.replace('\r\n', '\n')
with open(filename + '.hex', 'w') as hexfile:
hexfile.write(hex)