
Flat assembler: x86 assembler that does multiple passes to optimize machine code - vmorgulis
http://flatassembler.net/
======
ers35
See also: The newer flat assembler g, a generic assembler not tied to a
particular architecture. Download
[http://flatassembler.net/fasmg.zip](http://flatassembler.net/fasmg.zip) and
read docs/manual.txt. There are examples for 8086, 8052, AVR, and Java Virtual
Machine.
[http://board.flatassembler.net/topic.php?t=17952](http://board.flatassembler.net/topic.php?t=17952)

~~~
metafex
If I understand this right, fasm_g is the macro-language of fasm with some
additions and the ability to output bytes.

That's really quite something, is it yet comparable to the current fasm?

~~~
ers35
See the board post in my parent comment for a comparison to fasm 1 by the
author.

------
Grom_PE
The most interesting points of flat assembler are elegant syntax, "Same source
- same output" philosophy, and a very powerful macro system that consists of
preprocessing and assembling stage; the fasm preprocessor has been shown to be
turing-complete [0].

In 2008 I've played with it, creating macros that patch a binary file (and
used it to extend a closed-source Windows program [1]), made PE format from
scratch [2], a simple PE encryptor [3].

[0]:
[http://board.flatassembler.net/topic.php?t=6624](http://board.flatassembler.net/topic.php?t=6624)

[1]:
[http://board.flatassembler.net/topic.php?t=8876](http://board.flatassembler.net/topic.php?t=8876)

[2]:
[http://board.flatassembler.net/topic.php?t=8632](http://board.flatassembler.net/topic.php?t=8632)

[3]:
[http://board.flatassembler.net/topic.php?t=8951](http://board.flatassembler.net/topic.php?t=8951)

------
dang
We changed the URL from
[http://flatassembler.net/docs.php?article=manual#2.3.3](http://flatassembler.net/docs.php?article=manual#2.3.3)
to the root page because it looks like this project hasn't had attention on HN
before.

~~~
cfcef
A better link might be
[http://flatassembler.net/docs.php?article=design](http://flatassembler.net/docs.php?article=design)
which helps explain wtf this is and why anyone should care.

------
majke
The introduction to SSE is not bad
[http://flatassembler.net/docs.php?article=manual#2.1.15](http://flatassembler.net/docs.php?article=manual#2.1.15)

------
jwr
What would really get me excited is an assembler that does more intelligent
things — automatic register allocation at a minimum. I don't know why in 2015
I still have to manually track which register I'm using for what. This gets
particularly problematic with MMX/SSE/AVX registers. I think the x86 assembly
world would benefit from learning about features found in DSP assemblers (I'm
thinking of TI C6000 tools in particular).

~~~
claystu
Your wish has been granted. It's called C and it's been around since the 70's.

~~~
jwr
I will take an educated guess that none of the responders to my comment (and
I'll just post this one reply to all) have written significant amounts of
assembly code, especially using MMX/SSE/AVX, and so will respectfully disagree
with all of the responses.

Briefly:

* writing assembly in C is an exercise in frustration, just try to see anything past the syntax, same goes for intrinsics, with the added bonus of having to check whether the code you got is actually what you wanted, * no, you do not want to manually keep track of all of your 32 AVX-512 registers, trust me (for x86+SSE I used printed register allocation tables to help me track of what is where at which stage), heck, even on a measly ARM Cortex-M managing your R0-R12 (and not all instructions operate on all of them) can get annoying. The idea that you can keep registers in your head stems from the days when we had AX-DX to work with.

"Assembly" doesn't have to mean doing everything manually (and macros, yay!),
really. There is a middle ground, where you get a reasonably intelligent
assembler which does a lot of the manual grudge work for you. There are also
more intelligent assemblers which, for example, take your linear assembly and
convert it into VLIW, allocating processing units. Or reorder instructions
around branches.

Assembly language should be thought of as a spectrum of tools.

~~~
claystu
This is a serious question: what's the point of programming in assembly if you
don't want to control the registers? And what do you do if the assembler does
a poor job of register allocation? If you hand optimize it, you're back in
normal assembly; if you ignore it, you might as well not check in the first
place.

Once you sacrifice the registers, assembly just becomes a non-portable
programming language without any libraries. Unless you build it out with
macros and capitalize on it being a programmable programming language, but
then why not go with Forth or some kind of Lisp?

What does no-register assembly gain you that higher level languages don't
already offer?

------
gravypod
I've been looking for something like the FAT12 bootloader from the examples
section for some time.

Not really related to the main post, but still a big help!

------
wruza
The word "optimize" is overused here. Fasm makes multiple passes because it
allows forward references, and rich macro system makes it hard to guess
everything in 1-2 passes (it also removes lot of formalism from user). What is
actually optimized: jmp width.

