u/AppledogHu

Stuck trying to self-host from assembly

Hi! I wrote my own CPU emulator (the SD-8516), and I am trying to get a C compiler working on it. I have gotten quite far, the big thing was understanding the symbol table, but I got stuck because I made the symbol table only 16 bits and I had to rewrite everything because it couldn't hold a 24 bit pointer. Now it works and it can compile functions like strcmp and strlen (yay!) but I am completely lost as to what to do next. I'm getting a bit desperate. AI can't help me, it's not smart enough to figure this stuff out, and I am thinking, maybe I better try and rewrite it again. The problem is it's in assembly, so I have translate anything I get into my own custom assembly language. The faster I can get C up the better! Its currently a one pass compiler with no AST. My plan was to compile a C version of itself, but its getting too large to fit in my brain. Maybe what I need is to try rewriting it again but using ASTs? Whats an AST? ._.

Question: Are there any books that contain practical code examples, in C, that can be used during the bootstrapping process? Once I get a C version to compile itself I am sure I will be in business! Right now I can compile a kind of 'B with char pointers and arrays' (no for loops yet but we can do while). I had thought maybe there was a series of C compilers out there that could compile themselves and I could slowly bring up C that way. But now I realize its the same problem with trying to write a back-end. The C compiler is of course intimately connected with the system architecture. I wonder though, if there isn't some pseudo-code C compiler out there, somewhere, that I could study?

reddit.com
u/AppledogHu — 14 days ago