-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathassemble.py
43 lines (34 loc) · 975 Bytes
/
assemble.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
# imports
import os
import sys
# variables to make things simpler for myself
osys = os.system
sysargs = sys.argv
# main
def main():
# check that a file was actually input
try:
file = sysargs[1]
except:
# if not, throw an error
print("Enter the file you want to assemble.")
return
# call parse() to get the file name (fn) and the file extension (ext)
fn, ext = parse(file)
# it needs to be an assembly file, otherwise it won't work
if ext != 'asm':
print("The input file must be a '.asm' file.")
return
# define the commands
cmd1 = f'/masm32/bin/ml /c /Zd /coff {fn}.asm'
cmd2 = f'/masm32/bin/Link /SUBSYSTEM:CONSOLE {fn}.obj'
# call the commands
osys(cmd1)
osys(cmd2)
# function to parse the file name at the '.'
def parse(file):
fn, ext = file.split('.')
return fn, ext
# because this is meant to run in the console
if __name__ == "__main__":
main()