@@ -61,19 +61,19 @@ def append_section(self, value, expected_section=None):
61
61
self .offsets [s ] += value
62
62
else :
63
63
self .sections [s ].append (value )
64
- self .offsets [s ] += 1
64
+ self .offsets [s ] += len ( value )
65
65
66
66
def dump (self ):
67
67
print ("Symbols:" )
68
68
for label , section_offset in sorted (self .symbols .items ()):
69
69
print (label , section_offset )
70
70
print ("%s section:" % TEXT )
71
71
for t in self .sections [TEXT ]:
72
- print ("%08x" % t )
72
+ print ("%08x" % int . from_bytes ( t , 'little' ) )
73
73
print ("size: %d" % self .offsets [TEXT ])
74
74
print ("%s section:" % DATA )
75
75
for d in self .sections [DATA ]:
76
- print ("%08x" % d )
76
+ print ("%08x" % int . from_bytes ( d , 'little' ) )
77
77
print ("size: %d" % self .offsets [DATA ])
78
78
print ("%s section:" % BSS )
79
79
print ("size: %d" % self .offsets [BSS ])
@@ -88,20 +88,15 @@ def d_bss(self):
88
88
self .section = BSS
89
89
90
90
def d_skip (self , amount , fill = None ):
91
- # TODO fill should be 8bit, but we are currently filling with 32bit
92
91
s = self .section
93
92
amount = int (amount )
94
93
if fill is not None and s is BSS :
95
94
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
95
if s is BSS :
101
96
self .append_section (amount )
102
97
else :
103
- for i in range ( amount ):
104
- self .append_section (fill )
98
+ fill = int ( fill or 0 ). to_bytes ( 1 , 'little' ) * amount
99
+ self .append_section (fill )
105
100
106
101
d_space = d_skip
107
102
@@ -110,7 +105,7 @@ def assemble(self, lines):
110
105
if label is not None :
111
106
if label in self .symbols :
112
107
raise Exception ('label %s is already defined.' % label )
113
- self .symbols [label ] = (self .section , self .offsets [self .section ])
108
+ self .symbols [label ] = (self .section , self .offsets [self .section ] // 4 )
114
109
if opcode is not None :
115
110
if opcode [0 ] == '.' :
116
111
# assembler directive
@@ -125,7 +120,7 @@ def assemble(self, lines):
125
120
func = getattr (opcodes , 'i_' + opcode , None )
126
121
if func is not None :
127
122
instruction = func (* args )
128
- self .append_section (instruction , TEXT )
123
+ self .append_section (instruction . to_bytes ( 4 , 'little' ) , TEXT )
129
124
continue
130
125
raise Exception ('Unknown opcode or directive: %s' % opcode )
131
126
0 commit comments