A C compiler for the BBC Micro

discussion of beeb/electron applications, languages, utils and educational s/w
Post Reply
benjaminmisell
Posts: 3
Joined: Sun Apr 15, 2018 11:02 am
Contact:

A C compiler for the BBC Micro

Post by benjaminmisell » Sun Apr 15, 2018 12:05 pm

Hello all,

Over the past year I have been (slowly) building a C compiler in python for the BBC Micro. It's nothing special, just a learning experience. The code is available at https://github.com/benjaminmisell/bbc-c. I looking for some feedback on where to go next, or some possible improvements, also if any of you spot any mistakes please point them out to me in a github issue.

SteveF
Posts: 510
Joined: Fri Aug 28, 2015 8:34 pm
Contact:

Re: A C compiler for the BBC Micro

Post by SteveF » Sun Apr 15, 2018 3:29 pm

Always interesting to see new compiler projects! I haven't had a detailed look at this, but having had a quick poke at the git repo I think you might be generating subtly wrong code. brot.s is using OSASCI (&FFE3) to issue VDU commands, e.g.:

Code: Select all

LDA #22
JSR &FFE3
LDA #2
JSR &FFE3
You'll get away with that most of the time - including in this case - until you try to send &D through and it gets turned into &A, &D. Safest to just use OSWRCH (&FFEE) and save OSASCI for text output.

User avatar
tricky
Posts: 2558
Joined: Tue Jun 21, 2011 8:25 am
Contact:

Re: A C compiler for the BBC Micro

Post by tricky » Sun Apr 15, 2018 4:30 pm

Great project.
I haven't had a good look at the code as I seem to be allergic to python!
There is a 6502 optimiser around here somewhere that might be useful as part of a peephole optimiser.
Keep up the good work.

benjaminmisell
Posts: 3
Joined: Sun Apr 15, 2018 11:02 am
Contact:

Re: A C compiler for the BBC Micro

Post by benjaminmisell » Sun Apr 15, 2018 6:08 pm

SteveF: that is old test code that isn't really relevant to anything. If you look in my (very incomplete) libc then you will see the correct OSWRCH.

benjaminmisell
Posts: 3
Joined: Sun Apr 15, 2018 11:02 am
Contact:

Re: A C compiler for the BBC Micro

Post by benjaminmisell » Thu Apr 26, 2018 6:54 pm

I have a slight update.

I have implemented an assembler (in python again) that also outputs a DFS SSD disk image. I've followed the same design(ish) as the compiler. If you know youre way arround python then the assembler can be used on its own. Also, just a warning it uses the BBC BASIC & for hex rather than the standard 6502 $.

Post Reply