Missing intrinsics for gcc: see https://gcc.gnu.org/onlinedocs/gccint/Integer-library-routines.html#Integer-library-routines https://github.com/llvm-mirror/compiler-rt/tree/master/lib/builtins umodsi3 is for modulo with a constant (in this example, "... % 1000". ldu #1000 stu 6,s stx ,s sty 2,s leax 147,s jsr ___umodsi3 leas 8,s ldd 141,s aslb rola tfr d,x ldx _word,x stx 113,s ; no code to implement it yet. __umodsi3 (a, b) unsigned nongcc_SI_type a, b; { perform_umodsi3 (a, b); // a % b } COMPILER_RT_ABI su_int __umodsi3(su_int a, su_int b) { return a - __udivsi3(a, b) * b; } // This function should not call __divsi3! COMPILER_RT_ABI su_int __udivsi3(su_int n, su_int d) { const unsigned n_uword_bits = sizeof(su_int) * CHAR_BIT; su_int q; su_int r; unsigned sr; // special cases if (d == 0) return 0; // ?! if (n == 0) return 0; sr = __builtin_clz(d) - __builtin_clz(n); // 0 <= sr <= n_uword_bits - 1 or sr large if (sr > n_uword_bits - 1) // d > r return 0; if (sr == n_uword_bits - 1) // d == 1 return n; ++sr; // 1 <= sr <= n_uword_bits - 1 // Not a special case q = n << (n_uword_bits - sr); r = n >> sr; su_int carry = 0; for (; sr > 0; --sr) { // r:q = ((r:q) << 1) | carry r = (r << 1) | (q >> (n_uword_bits - 1)); q = (q << 1) | carry; // carry = 0; // if (r.all >= d.all) // { // r.all -= d.all; // carry = 1; // } const si_int s = (si_int)(d - r - 1) >> (n_uword_bits - 1); carry = s & 1; r -= d & s; } q = (q << 1) | carry; return q; } S _divhi3 Ref0000 ; [468] cows = score%5; bulls = score/5; ldd #5 std ,--s leax ,y jsr _modhi3 leas 2,s stx 2,s ldd #5 std ,--s leax ,y jsr _divhi3 leas 2,s leay ,x #ifdef L_divhi3 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ___divhi3 - signed division ;;; Arguments: Dividend in X, divisor on the stack ;;; Returns result in X. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; .area .text .globl _divhi3 _divhi3: ldd 2,s bne do_div ; check dividend SIGFPE do_div: pshs x jsr _seuclid puls x,pc #endif S _modhi3 Ref0000 752 ; [486] cows = your_score%5; 02B8 CC 00 05 753 ldd #5 02BB ED E3 754 std ,--s 02BD AE E8 12 755 ldx 18,s 02C0 BD 00 00 756 jsr _modhi3 02C3 32 62 757 leas 2,s 02C5 AF 6E 758 stx 14,s #ifdef L_modhi3 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ___modhi3 - signed modulo ;;; Arguments: Dividend in X, divisor on the stack ;;; Returns result in X. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; .area .text .globl _modhi3 _modhi3: ldd 2,s bne do_mod ; check dividend SIGFPE do_mod: pshs x jsr _seuclid leas 2,s tfr d,x rts #endif Some I/O is predeclared. Printf sometimes gets converted into putchar or puts if param is a single character or a string with no % parameters embedded. S _putchar Ref0000 S _puts Ref0000 S _printf Ref0000 S _getchar Ref0000