Get the latest tech news

A Proper x86 Assembler in Haskell Using the Escardó-Oliva Functional


Writing an assembler turns out to be an interesting example: one needs to calculate distances between jumps and their target labels, and the target may appear after the label. It turns out that one can write a one-pass assembler using the tardis monad or in Curry, using logic programming.

In our case the problem can be thought of as a single-player game; the outcome is the number of bytes required to assemble the code, which we would like to minimize. The optimal play (here, the assignment of jumps to encodings leading to the smallest code) is provided by The next part is fairly standard---we collect offsets of labels---with the subtlety that we can assume all jumps are short if they have not been specified yet; invalid assignments will be pruned later.

Get the Android app

Or read this on Hacker News

Read more on:

Photo of Haskell

Haskell

Photo of oliva functional

oliva functional

Photo of proper x86 assembler

proper x86 assembler

Related news:

News photo

Haskell: A Great Procedural Language

News photo

Overloading the lambda abstraction in Haskell (2022)

News photo

Haskell vs. Ada vs. C++ vs. an Experiment in Prototyping Productivity (1994) [pdf]