User Tools

Site Tools


sd:sdcc

Table of Contents

SD/CC

  • SD/CC is TinyC for the SD-8516.

Introduction

A self-hosted C compiler has been my goal for quite some time. I did BASIC and Forth first. BASIC was useful, Forth – not so much (from a practical standpoint).

At the end of March I was able to get something set up where it could compile:

  int main(void) { return 0; }

The problem was that isn't very much. Weeks went by and I couldn't figure it out. It was supposed to be just like the BASIC expression parser. A recursive descent parser. So the first thing I added was additive and multiplicative expressions. Then suddenly it started working. I honestly don't know what changed because it wasn't working then suddenly it was and I couldn't remember changing anything in the code.

cc_parse_expr:
    ; Parse left operand
    CALL @cc_parse_term

    ; Check error
    LDAL [@CC_ERROR]
    CMP AL, #0
    JNZ @cc_pe_done

cc_pe_loop:
    ; Check for '+' or '-'
    LDAL [@CC_TOKEN_TYPE]

    CMP AL, TOK_PLUS
    JZ @cc_pe_add

    CMP AL, TOK_MINUS
    JZ @cc_pe_sub

This works for + and -, we can return 3+5 now. Next I added negative numbers. I had to add a check for TOK_MINUS first and then emit a SUB A, B to get it to negate.

Integers

  • April 14th, 2026.

I've been trying to get a symbol table up and to define int; but it isn't working. I think there is an off by one bug on the stack. Storing variables on the stack is something I don't fully understand or trust yet.

What is really biting me in the ass is the system I came up with to pair 16-bit registers into 24-bit pointers. It's a charmingly retro, period-authentic thing. But it makes coding a bit hard when you need multiple pointers. I have a 'secret weapon' – the ability to add more registers any time I want, but, I want to avoid going down that route if possible. Having so many registers already is supposed to be good enough.

More to come.

sd/sdcc.txt · Last modified: by appledog

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki