View unanswered posts | View active topics It is currently Sun Mar 29, 2020 6:52 am



Reply to topic  [ 33 posts ]  Go to page Previous  1, 2, 3
 Some C compilers 
Author Message

Joined: Wed Nov 20, 2019 12:56 pm
Posts: 28
roelh wrote:
Hi all, my C compiler is now integrated into the Kobold K2 online Javascript assembler/simulator.

On a single browser page you can now compile, assemble and simulate the C code, and download a file to program into the Kobold.

See it live at http://www.enscope.nl/simas_kobold2/ !


Very impressive - nice work!
It looks like you can now cope with the working set not fitting within registers - how did you approach register allocation / spillage?


Wed Mar 11, 2020 10:57 pm
Profile

Joined: Mon Oct 07, 2019 1:26 pm
Posts: 36
Thank you Robinson ! About the register allocation:

The workspace holds max 16 locals in RAM. At a function call, the workspace pointer WP is incremented by 32, so now the called function
has 16 fresh local variables (but for leaf functions the locals are in zpage, this saves the instructions needed to change WP).
There are 8 registers (4 data and 4 address). PC (A0) and WP(A1) are address registers, and one register is needed for the return address, this leaves 5 registers for parameter passing. So the max nr of parameters is 5. This could be extended by having another parameter pass convention for parameter 6 and higher, for instance they could be directly placed into the next workspace).

Calculations normally are done in register D3. This is also the register for function results and for the first parameter of a function call. Within the code generator, there is a function that returns a new register to use (and reserves it), but it is currently only used one level deep. Address calculations are mostly done in D2 and A2.

For expressions, the code generator will first generate code for the deepest branch of the expression. This minimizes the number of intermediate results. But if intermediate results must be stored, this is generally done in the workspace.

The code generator does several other optimizations that will be described later.

There are no compare instructions in the Kobold instruction set, a subtract must be used (that is an add with the 2's complement). So the register that is compared will be changed after the instruction. But there are also ADD instructions that deliver the result in an address register, like:

MOVC (var),D3 ; variable to D3 and complement it
ADDI 45,D3,A3 ; add and increment. Comparison result comes in carry.

This can used for compare. The D3 value is not changed, and the result in A3 is simply ignored.

You can have a look at the code generator here: http://www.enscope.nl/simas_kobold2/generator.js


Thu Mar 12, 2020 8:46 am
Profile

Joined: Wed Jan 09, 2013 6:54 pm
Posts: 1384
Nice - can confirm, 3 is prime, and 9 isn't. (You might find that a fast-forward function will help a lot - allow for multiple steps between GUI updates. Ken's calculator simulator runs a few hundred(?) steps at normal speed and then speeds up. Visualy6502 takes a parameter to adjust the fast-forward button's step length.)


Thu Mar 12, 2020 9:29 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 33 posts ]  Go to page Previous  1, 2, 3

Who is online

Users browsing this forum: No registered users and 1 guest


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 post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group
Designed by ST Software