Stephen Tu
2008-08-03 06:00:53 UTC
So since hand-assembling mips -> hex isn't exactly that fun, i have
wrote a simple assembler script. you can run it by invoking the command:
~cs61c-aq/public/bin/assembler [path_to_mips_file]
it can also read from STDIN, so you can pipe input into it. say you want
to convert a single command but dont want to save to file:
echo "add $r0,$r1,$r2" | ~cs61c-aq/public/bin/assembler
the program returns hex instructions to STDOUT, so if you want to save
it to a file just redirect the output:
~cs61c-aq/public/bin/assembler [path_to_mips_file] > myfile.hex
as for the syntax of the MIPS that it can read, it is mostly like
regular mips (it's not whitespace sensitive, and you can put comments in
your code w/ hashes (#)). several differences to note:
1) the op for jump is "jump" not "j"
2) for immediates, you can only put in positive decimal values as of
now. you can't do negative values and you can't do hex values yet. if
somebody wants to add this feature, please do so, b/c i'm too lazy to :)
3) for lw/sw, the offset part is _not_ whitespace sensitive. meaning
lw $r0, 0( $r1 ) is not valid and neither is lw $r0, 0 ($r1)
NOTE: i tried to test it on every case, but i'm sure i missed one or
two. please let me know when the program is giving incorrect hex
translations. don't expect it to be 100% accurate yet. if you find any
bugs let me know or better yet, post a diff of a fix and i'll apply it
as a patch :). it's just a simple perl script so you can all see the
source code
finally, i tried to make sure everybody has permissions to access it,
but in case it doesn't work, let me know. you might have to cp the
script to your own directory if it has issues opening your saved text
files due to lack of permissions. hopefully this script is helpful to
you guys until albert posts his assembler.
wrote a simple assembler script. you can run it by invoking the command:
~cs61c-aq/public/bin/assembler [path_to_mips_file]
it can also read from STDIN, so you can pipe input into it. say you want
to convert a single command but dont want to save to file:
echo "add $r0,$r1,$r2" | ~cs61c-aq/public/bin/assembler
the program returns hex instructions to STDOUT, so if you want to save
it to a file just redirect the output:
~cs61c-aq/public/bin/assembler [path_to_mips_file] > myfile.hex
as for the syntax of the MIPS that it can read, it is mostly like
regular mips (it's not whitespace sensitive, and you can put comments in
your code w/ hashes (#)). several differences to note:
1) the op for jump is "jump" not "j"
2) for immediates, you can only put in positive decimal values as of
now. you can't do negative values and you can't do hex values yet. if
somebody wants to add this feature, please do so, b/c i'm too lazy to :)
3) for lw/sw, the offset part is _not_ whitespace sensitive. meaning
lw $r0, 0( $r1 ) is not valid and neither is lw $r0, 0 ($r1)
NOTE: i tried to test it on every case, but i'm sure i missed one or
two. please let me know when the program is giving incorrect hex
translations. don't expect it to be 100% accurate yet. if you find any
bugs let me know or better yet, post a diff of a fix and i'll apply it
as a patch :). it's just a simple perl script so you can all see the
source code
finally, i tried to make sure everybody has permissions to access it,
but in case it doesn't work, let me know. you might have to cp the
script to your own directory if it has issues opening your saved text
files due to lack of permissions. hopefully this script is helpful to
you guys until albert posts his assembler.