2015-06-16 22:33:26 +00:00
|
|
|
# Hack Assembler in Haskell
|
|
|
|
|
2015-06-18 19:40:14 +00:00
|
|
|
* [Introduction](#introduction)
|
|
|
|
* [Building](#building)
|
|
|
|
* [Usage](#usage)
|
|
|
|
* [Tools](#tools)
|
|
|
|
* [License](#license)
|
|
|
|
* [Issues](#issues)
|
|
|
|
* [Related Projects](#related-projects)
|
2015-06-18 15:01:18 +00:00
|
|
|
|
2015-06-18 19:40:14 +00:00
|
|
|
## Introduction <a name="introduction"></a>
|
2015-06-18 15:01:18 +00:00
|
|
|
|
|
|
|
`Asmblr` is a small Haskell program that transforms *Hack Assembly* into its machine language
|
|
|
|
representation. The parser itself is made available though the library `hackasm` and can be
|
|
|
|
included in other projects. To see its documentation run `cabal haddock` and view the
|
|
|
|
documentation in `dist/doc`.
|
2015-06-16 22:33:26 +00:00
|
|
|
|
2015-06-18 19:40:14 +00:00
|
|
|
## Features <a name="features"></a>
|
2015-06-16 22:33:26 +00:00
|
|
|
|
|
|
|
* Follows a similar structure to the implementation describe by the *Nand to Tetris* book
|
|
|
|
* Faster then the implementation given with the *Nand to Tetris* course
|
|
|
|
* Can read from stdin and write to stdout (if requested)
|
|
|
|
* Uses open-source tools wherever possible
|
|
|
|
|
2015-06-18 19:40:14 +00:00
|
|
|
## Building <a name="building"></a>
|
2015-06-16 22:33:26 +00:00
|
|
|
|
|
|
|
`Asmblr` requires GHC and cabal to be built and can be done like so:
|
|
|
|
|
|
|
|
$ cabal configure
|
|
|
|
$ cabal build
|
|
|
|
|
2015-06-18 15:01:18 +00:00
|
|
|
Once built, the `Asmblr` executable will be in the `dist/build/Asmblr` folder, and can be run
|
|
|
|
using you shell or cabal (via the command `cabal run Asmblr`). The `Asmblr` program can also be
|
|
|
|
installed using `cabal install`. For more information on installing cabal packages and using
|
|
|
|
cabal see [its manual](https://www.haskell.org/cabal/users-guide/).
|
|
|
|
|
2015-06-18 19:40:14 +00:00
|
|
|
## Usage <a name="usage"></a>
|
2015-06-18 15:01:18 +00:00
|
|
|
|
|
|
|
This project comes with the directory `doc/examples` that contains example *Hack Assembly*
|
|
|
|
programs used for testing the assembler. To clarify how to run the `Asmblr` binary once built
|
|
|
|
we will use of of the aforementioned *Hack Assembly* files as an input, in this case
|
|
|
|
`doc/examples/Pong.asm`.
|
|
|
|
|
|
|
|
Running the `Asmblr` using cabal:
|
|
|
|
|
|
|
|
$ cabal run Asmblr -- doc/examples/Pong.asm
|
|
|
|
|
|
|
|
Running the `Asmblr` using POSIX shell:
|
|
|
|
|
|
|
|
$ ./dist/build/Asmblr/Asmblr doc/examples/Pong.asm
|
|
|
|
|
|
|
|
Both of the previous commands invoke the `Asmblr` on the file `doc/examples/Pong.asm` and
|
|
|
|
generate a file `Pong.hack` in the current directory. `Asmblr` also supports taking input from
|
|
|
|
`stdin` as well as writing its output to `stdout` or an arbitrary file given by the user. For
|
|
|
|
convenience the output of `Asmblr --help` is provided below.
|
|
|
|
|
|
|
|
Usage: Asmblr [OPTION...] file
|
|
|
|
-v --verbose chatty output on stderr
|
|
|
|
-V --version show version number
|
|
|
|
-h --help show program usage
|
|
|
|
-o[FILE] --output[=FILE] output file or '-' for stdout
|
2015-06-16 22:33:26 +00:00
|
|
|
|
2015-06-18 19:40:14 +00:00
|
|
|
## Tools <a name="tools"></a>
|
2015-06-16 22:33:26 +00:00
|
|
|
|
|
|
|
The creation of this software was made possible by the following open source tools and
|
|
|
|
libraries.
|
|
|
|
|
|
|
|
* [Gnu Emacs][], because there is no place like home; and no greater editor!
|
|
|
|
* [GHC][], for compilation of Haskell code
|
|
|
|
* [Cabal][], for building the project
|
|
|
|
|
2015-06-18 19:40:14 +00:00
|
|
|
## License <a name="license"></a>
|
2015-06-16 22:33:26 +00:00
|
|
|
|
2015-06-18 15:01:18 +00:00
|
|
|
This project is licensed under the [GPLv3][]. Please see the [LICENSE](../tree/LICENSE) file for full details.
|
2015-06-16 22:33:26 +00:00
|
|
|
|
2015-06-18 19:40:14 +00:00
|
|
|
## Issues <a name="issues"></a>
|
2015-06-16 22:33:26 +00:00
|
|
|
|
2015-06-18 15:01:18 +00:00
|
|
|
There are some minor issues that can be cleaned up in future releases. Namely, making error
|
|
|
|
output more human readable, and a few minor optimization's.
|
2015-06-16 22:33:26 +00:00
|
|
|
|
|
|
|
* Explicitly handle if input file dne or is unreadable
|
|
|
|
* Explicitly handle if output file is un-writable
|
2015-06-18 15:01:18 +00:00
|
|
|
* Create ParseException type to throw from parser and can be caught in
|
|
|
|
`RekahSoft.HackAsm.CommanLine.defaultMain`
|
|
|
|
* Add `(<?> "error description")` throughout parsers to make error output more readable
|
2015-06-16 22:33:26 +00:00
|
|
|
* Write tests so that future changes don't break things (see folder `testsuite`)
|
|
|
|
|
2015-08-04 00:29:38 +00:00
|
|
|
If you discover a bug or have an issue with this project, please file a bug using
|
|
|
|
the [Rekahsoft flyspray powered bug tracker](https://bugs.rekahsoft.ca/index.php?project=8).
|
|
|
|
|
2015-06-18 19:40:14 +00:00
|
|
|
## Related Projects <a name="related-projects"></a>
|
2015-06-18 15:01:18 +00:00
|
|
|
|
|
|
|
The *Hack Machine Code* generated by this assembler is only useful if a *Hack* machine or
|
|
|
|
simulator is available. One such simulator is available with the *Nand to Tetris* course.
|
|
|
|
Alternatively, I've written a
|
|
|
|
[VHDL implementation of the Hack Platform](http://git.rekahsoft.ca/hack) which can be used to
|
|
|
|
simulate the *Hack Machine* in order to run the assembly generated by this assembler. Currently
|
|
|
|
it is not as full featured and user friendly as the simulator given by the *Nand to Tetris*
|
|
|
|
course, and likely never will be as it's end goal is to be implemented on a FPGA with
|
2015-12-08 04:57:28 +00:00
|
|
|
verification of the design done via simulation. For more details see
|
2015-06-18 15:01:18 +00:00
|
|
|
[its README](http://git.rekahsoft.ca/hack/about).
|
|
|
|
|
2015-06-16 22:33:26 +00:00
|
|
|
[Gnu Emacs]: http://www.gnu.org/software/emacs/
|
|
|
|
[GPLv3]: https://www.gnu.org/licenses/gpl.html
|
|
|
|
[GHC]: https://www.haskell.org/ghc/
|
|
|
|
[Cabal]: https://github.com/haskell/cabal/
|