@@ -10,7 +10,7 @@ class Assembler:
10
10
11
11
def __init__ (self ):
12
12
self .symbols = {}
13
- self .sections = dict (text = [], data = [], bss = 0 )
13
+ self .sections = dict (text = [], data = [])
14
14
self .offsets = dict (text = 0 , data = 0 , bss = 0 )
15
15
self .section = TEXT
16
16
@@ -56,24 +56,27 @@ def append_section(self, value, expected_section=None):
56
56
s = self .section
57
57
if expected_section is not None and s is not expected_section :
58
58
raise TypeError ('only allowed in %s section' % expected_section )
59
- if s is TEXT or s is DATA :
59
+ if s is BSS :
60
+ # just increase BSS size by value
61
+ self .offsets [s ] += value
62
+ else :
60
63
self .sections [s ].append (value )
61
64
self .offsets [s ] += 1
62
- elif s is BSS :
63
- self .sections [s ] += value # just increase BSS size by value
64
65
65
66
def dump (self ):
66
67
print ("Symbols:" )
67
68
for label , section_offset in sorted (self .symbols .items ()):
68
69
print (label , section_offset )
69
70
print ("%s section:" % TEXT )
70
71
for t in self .sections [TEXT ]:
71
- print (hex (t ))
72
+ print ("%08x" % t )
73
+ print ("size: %d" % self .offsets [TEXT ])
72
74
print ("%s section:" % DATA )
73
75
for d in self .sections [DATA ]:
74
- print (d )
76
+ print ("%08x" % d )
77
+ print ("size: %d" % self .offsets [DATA ])
75
78
print ("%s section:" % BSS )
76
- print ("size: %d" % self .sections [BSS ])
79
+ print ("size: %d" % self .offsets [BSS ])
77
80
78
81
def d_text (self ):
79
82
self .section = TEXT
@@ -84,6 +87,24 @@ def d_data(self):
84
87
def d_bss (self ):
85
88
self .section = BSS
86
89
90
+ def d_skip (self , amount , fill = None ):
91
+ # TODO fill should be 8bit, but we are currently filling with 32bit
92
+ s = self .section
93
+ amount = int (amount )
94
+ if fill is not None and s is BSS :
95
+ raise ValueError ('fill not allowed in section %s' % s )
96
+ fill = int (fill or 0 )
97
+ if amount % 4 :
98
+ amount += 4 - amount % 4
99
+ amount = amount // 4
100
+ if s is BSS :
101
+ self .append_section (amount )
102
+ else :
103
+ for i in range (amount ):
104
+ self .append_section (fill )
105
+
106
+ d_space = d_skip
107
+
87
108
def assemble (self , lines ):
88
109
for label , opcode , args in self .parse (lines ):
89
110
if label is not None :
0 commit comments