flat assembler
Message board for the users of flat assembler.

Index > High Level Languages > I Made A Basic Compiler With FASM as Backend

Author
Thread Post new topic Reply to topic
Excalibur



Joined: 01 Apr 2025
Posts: 1
Excalibur 01 Apr 2025, 04:16
Hi all,

I have a heavy interest in designing high level languages and have made a fairly flexible (but unoptimized) interpreted language in the past, but now am turning to compiled languages. As a project to help learn fasm and compiler design I have made a small (unoptimized) toy language with FASM as the backend I'm calling codecalc, since it only has 64-bit integers and arrays.

If anyone would like to check it out the repo is here:
https://github.com/Excalibur277/codecalc

I've really appreciated the great resources to help learn fasm on these threads, so thanks a bunch. The compiler backend is very unoptimized, with a lot of register spilling, and results in code around 2x slower than compiled c for an equivalent speed test. Main cause for this is that currently expressions always place the resultant in rax (and often push to the stack), and assigned variables are always pushed to the stack, leading to far more memory usage than achievable when tracking registers properly.

My next steps will likely be to experiment around with creating a intermediatory language (like LLVM IR) that is platform agnostic so I can experiment with optimizations such as:

- Register allocation algorithms to reduce spilling and allow me not to use RAX for everything Razz
- Constant expression precalculation
- Look more in depth into writing code that works well with branch prediction.

Any thoughts about what else i can improve in my use of fasm would be great.
Post 01 Apr 2025, 04:16
View user's profile Send private message Reply with quote
ground



Joined: 25 May 2024
Posts: 2
Location: The Netherlands
ground 15 Apr 2025, 20:50
Hi Excalibur, Thanks for sharing the url. Your choice for GO as the implementation language is good. Microsoft is rewriting the Typescript compiler with Go, so you are in good company. Smile
By the way, I also have a toy language (Ground language) that generates some simple assembler code. Implemented in C#. I will post the URL in this thread. Maybe nice for you to look at for inspiration. But please do continue with your own language. It is fun to have your own language.
Post 15 Apr 2025, 20:50
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.