class AssemblerError(Exception):
def __init__(self
,*args
):
Exception.__init
__(self
,args
)
asm() takes a string of assembly code and produces a list of
instruction words. When asm() is passed a list of strings it
will produce a list of list of instruction words. For example
asm('done;nop') returns [0x81f00000,0x1000000] and
asm(['done','nop']) returns [[0x81f00000],[0x1000000]].
[result
.append(asm_instr(i
)) for i
in instr
]
result
= asm_instr(instr
)
s_name
= tempfile
.mktemp(suffix
=".s")
o_name
= tempfile
.mktemp(suffix
=".o")
d_name
= tempfile
.mktemp(suffix
=".d")
e_name
= tempfile
.mktemp(suffix
=".2")
t_name
= tempfile
.mktemp(suffix
=".t")
s_file
= open(s_name
,'w')
".register %g2,#scratch\n",
".register %g3,#scratch\n",
".register %g6,#scratch\n",
".register %g7,#scratch\n",
s_exec
= "%s -xarch=v9c -o %s %s 2> %s" % (as,o_name
,s_name
,e_name
)
if os
.system(s_exec
) == 0:
d_exec
= "%s %s | /bin/awk '{print $2$3$4$5}' | %s '^[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]' > %s 2> /dev/null" % (dis
,o_name
,grep
,d_name
)
if os
.system(d_exec
) == 0:
s_list
= [int(nr
,16) for nr
in d_file
.readlines()]
t_exec
= "/bin/sed -e 's/[^:]*:[^:]*:\ //g' %s > %s" % (e_name
,t_name
)
t_file
= open(t_name
,'r')
if __name__
== '__main__':
print asm("adx %g0, %g1, %g2")
print asm("add %g4, %g5, %g3\nadd %g0, %g1, %g2")
print asm(['add %g0, %g1, %o6', 'asd %g7, %g6, %g2'])
except AssemblerError
, e
: