Hacker News new | past | comments | ask | show | jobs | submit login

I'm porting LLVM/Clang to the 6502. Notoriously difficult project, attempted dozens of times by as many folks.

https://github.com/mysterymath/clang6502

My take generates pretty darn good assembly for the cases it handles, but it's absurdly incomplete. Still, a huge amount of risk factors have already been addressed, and there's only a few big known unknowns left.

Example input:

  void print_int(char x) {
    if (x < 10) {
      x += '0';
      asm volatile ("JSR\t$FFD2" : "+a"(x));
      return;
    }
    print_int(x / 10);
    print_int(x % 10);
  }
Example output:

  .code
  .global print__int                      ; -- Begin function print_int
  print__int:                             ; @print_int
  ; %bb.0:                                ; %entry
    CMP #10
    BMI LBB0__2
  ; %bb.1:                                ; %if.end.preheader
    LDX #10
    PHA                                     ; 1-byte Folded Spill
    JSR ____udivqi3
    JSR print__int
    PLA                                     ; 1-byte Folded Reload
    LDX #10
    JSR ____umodqi3
  LBB0__2:                                ; %if.then
    CLC
    ADC #48
    ;APP
    JSR $FFD2
    ;NO_APP
    RTS
                                        ; -- End function
  .global ____udivqi3
  .global ____umodqi3



OMF:2097 profile picture spotted! Loved the game as a child.

Will the compiler support 65C02 instructions?


Shouldn't be too hard to add later, since they're mostly just swizzles onto the existing instructions, and LLVM already has good support for registering slightly different versions of a target (subtargeting).

For now, I'm targeting the plain-jane MOS chip, since it's the buggiest and least capable, and thus the most difficult.




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: