A toy MSP430 assembler using recursive descent parsing for fast and efficient operation
Go to file
John Breaux 417ef03e41 0.2.0: Feature update and Refactor
- Each major module (lexer, parser, assembler) has its own error type
  - These error types are somewhat interconnected, but their
    dependency relationships are one-way and well defined
- The AST is no longer responsible for assembling itself
  - The Assembler (assembler::Assembler) will now visit every AST node
    and accumulate words
  - Words are assumed to be little-endian.
- There are now a set of assembler directives that affect the
  generated output:
  - .word <Number>: inserts a single word in the output
  - .words [<Number>,*]: inserts multiple words in the output
  - .byte <Number>: Alias for .word
  - .bytes [<Number>,*]: Alias for .words
  - .string "String": inserts a null-terminated UTF-8 encoded string
  - .strings ["String",*]: "" multiple strings
  - Data is always word-aligned at the moment.
- There are now assembler directives that affect the AST during
  parsing:
  - .include "path/to/file": Parses the contents of a file directly
    into the AST
    - Included files have their own defines, but *share* labels.
      This is because .defines are a tokenizer construct, and
      including a file creates a new buffer and tokenizer.
    - Circular includes are NOT checked for at the moment.
      It is very easy to exhaust the stack.
- General cleanup of several functions, comments, TODOs, etc.
- main.rs was moved to make room for upcoming improvements to the UI

TODO:
- REPL mode is only partially compatible with .define directive
- Branching to a label will branch to the data AT the label,
  not the label itself. I doubt this is correct behavior.
  - In case br <label> is meant to use the absolute address,
    I've created a .org directive (currently unimplemented)
    for specifying the load address of the program.
2023-09-05 01:54:50 -05:00
src 0.2.0: Feature update and Refactor 2023-09-05 01:54:50 -05:00
.gitignore Update gitignore 2023-08-19 23:55:41 -05:00
.rustfmt.toml msp430-asm: init repo with proof-of-concept code 2023-08-19 23:02:24 -05:00
Cargo.toml 0.2.0: Feature update and Refactor 2023-09-05 01:54:50 -05:00
readme.md Add readme.md 2023-08-20 00:53:35 -05:00
valid.asm 0.2.0: Feature update and Refactor 2023-09-05 01:54:50 -05:00

msp430-asm

A toy assembler for the TI MSP430, built with MicroCorruption in mind.

Usage

msp430-asm [-|-f|--file]

The frontend isn't very smart. It does no fancy arg parsing, no key interpretation or cursor manipulation or TUI goodness that everyone knows and loves. It does four things: Read. Evaluate. Print. Loop. Basic REPL. It doesn't even check whether you're running interactively or not.

By default, the assembler operates in repl mode, and each line is treated in isolation. This is great for quickly looking up an instruction.

To parse an entire file at once, and get useful context when there's a parse error, pipe it in through stdin with - as such:

cat valid.asm | msp430-asm -f

You can press Ctrl+D on Linux to emit an EOF over the terminal.

Motivations

  • Microcorruption's assembler sucks
  • I got tired of stringly-typed Python
  • I wanted to write a parser
  • I wanted to write Rust
  • I'm a fan of interactive programs