What's in an assembler?

Summary:

  1. Langdev crash course
  2. Case study: a particular assembler from the 90's
    1. Quick intro
    2. Language's design
    3. Design takeaways

Langdev crash course

How does a compiler work, anyway?

01110100101010100101110110101000SourcecodeAssemblerExecutable
SourcecodeLexer...TokensParser...SemanticsCodegenExecutable

Lexer? Parser?

Difference between lexer and parser

Consider:

  • fjshdfoilu gdiyuktf ggdbkifucqjuhzsiudmfppoe arzej
  • now a sentence this like, but none sense makes

→ token ≅ word

Codegen

After parsing: semantics

Roughly, instructions for code generation

A (really tough) science and an art

Thankfully trivial for an assembler 🙃

Case study:

RGBDS

A cautionary tale:

RGBDS

RGBDS

Background

Born in 1997

Pile of 90's-style C code 🐛

Claim to fame: used for some commercial releases!

Very 90's design...

Design points

Macro assembler

Unlimited relocation complexity

Human-oriented

Tangent: two kinds of assembler

Human-oriented:
  • Featureful
  • Conveniences
Compiler-oriented:
  • Uniform
  • Predictable

Sometimes at odds, but possible to marry both with enough effort

90's design, you say?

Let's witness some design lessons

...primarily negative.

PURGE

Metaprogramming facilities

Compile-time variables to store info

Uh-oh, no namespacing!

PURGE

Let's allow deleting symbols!

Metaprogramming

Metaprogramming

EQUS = compile-time eval

Imagine C macros, but there is no preprocessor

Fully text-based, bypassing tokens

→ Can't even lex a line until previous one is processed

Metaprogramming

Insanely powerful

Structs

RGBASM doesn't support structs

 

And now it does!

Brainfuck interpreter

Yes, really.

; hello world
	bf ++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++.
; echo
	bf \,+[-.\,+], HELLO WORLD!\n

Horribly unmaintainable

(Image missing)

Design takeaways

Language design

  • Processing in passes = better
  • Metaprogramming = good, actually

Design in general

  • Simplicity is a lie
  • Good to think about implications of a design
  • Oh how far we've come

EOF

Thank you for listening!