User Tools

Site Tools


assemblyscript_in_c

This is an old revision of the document!


AssemblyScript in C

If I had known that the project would be as difficult as it turned out, I just would have done the whole thing in C.

It's too late for that now, and I can't break 100 MIPS on a baseline system (GeekBench i7-12700K). Well, that isn't entirely true. This is the story of how I broke the 100 MIPS barrier.

The Best AssemblyScript can do

After several attempts at optimizing instructions I managed to get LDA to 95 MIPS, STA to 80 MIPS, DEC to 95 and NOP to 115. The NOP was easy as it's basically just a function call.

Next I tried the typical 'leader function' approach:

export function cpu_step(): void {

    const IP_now = _IP;
    let opcode = fetch_byte();

    // leader function
    let c_result = c_cpu_step(opcode);
    if (c_result === 0) {
        // C handled it successfully, we're done
        return;
    }

    switch(opcode) {
        ///////////////////////////////////////////////////////////////////////
        // LDR/STR load and store architexture                               //
        ///////////////////////////////////////////////////////////////////////
        case OP.LD_IMM: {
            ...

assemblyscript_in_c.1768615761.txt.gz · Last modified: by appledog

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki