forked from scotws/TaliForth2
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathreverse_asm.py
executable file
·53 lines (34 loc) · 1004 Bytes
/
reverse_asm.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
# Reverse assembler header sequence
# Scot W. Stevenson <[email protected]>
# First version: 30. Dez 2018
# This version: 30. Dez 2018
# This is a one-shot program to reverse the order of entries for the assembler
# wordlist in headers.asm.
import string
SOURCE = 'asm_headers.asm'
previous_link = '0000' # Start with end of list
src = []
dest = []
block = []
def is_link(s):
"""Takes a line from the listing and returns a bool depending on
if the line is a link or not.
"""
r = True
ws = s.split()
if (len(ws) != 2) or (ws[0] != '.word'):
r = False
return r
with open(SOURCE, 'r') as source_file:
src = source_file.readlines()
last_line = len(src)-1
for l in range(last_line, -1, -1):
line = src[l]
if is_link(line):
link = line.split()[1]
line = " "*16 +".word "+previous_link
if line[0] == 'n':
previous_link = line.strip()[:-1]
dest.insert(0, line)
for l in dest:
print(l.rstrip())