Added step counter
Fixed typo
A simple fractran interpreter, written in ANSI C.
cc fractran.c -std=c89 -Os -DNDEBUG -g0 -s -Wall -o fractran
A valid input begins with the accumulator state, followed by a series of positive fractions. If the accumulator value is 1008(2⁴ × 3² × 7), r2 has the value 4, r3 has the value 2, r7 has the value 1, and all other registers are unassigned.
Adding the values stored in the registers 2 and 3, and storing the result in the register 3.
3888 2/3
3888 2/3
r02=04 r03=05
3888 × 2/3 = 2592/1
r02=05 r03=04
2592 × 2/3 = 1728/1
r02=06 r03=03
1728 × 2/3 = 1152/1
r02=07 r03=02
1152 × 2/3 = 768/1
r02=08 r03=01
768 × 2/3 = 512/1
r02=09
512 × 2/3 = 1024/3
r02=09
Multiplying the values stored in the registers 2 and 3, and storing the result in the register 5.
36 385/13 13/21 1/7 3/11 7/2 1/3
r02=02 r03=02
36 × 385/13 = 13860/13
36 × 13/21 = 156/7
36 × 1/7 = 36/7
36 × 3/11 = 108/11
36 × 7/2 = 126/1
r02=01 r03=02 r07=01
126 × 385/13 = 48510/13
126 × 13/21 = 78/1
r02=01 r03=01 r13=01
78 × 385/13 = 2310/1
r02=01 r03=01 r05=01 r07=01 r11=01
2310 × 385/13 = 889350/13
2310 × 13/21 = 1430/1
r02=01 r05=01 r11=01 r13=01
1430 × 385/13 = 42350/1
r02=01 r05=02 r07=01 r11=02
42350 × 385/13 = 16304750/13
42350 × 13/21 = 78650/3
42350 × 1/7 = 6050/1
r02=01 r05=02 r11=02
6050 × 385/13 = 2329250/13
6050 × 13/21 = 78650/21
6050 × 1/7 = 6050/7
6050 × 3/11 = 1650/1
r02=01 r03=01 r05=02 r11=01
1650 × 385/13 = 635250/13
1650 × 13/21 = 7150/7
1650 × 1/7 = 1650/7
1650 × 3/11 = 450/1
r02=01 r03=02 r05=02
450 × 385/13 = 173250/13
450 × 13/21 = 1950/7
450 × 1/7 = 450/7
450 × 3/11 = 1350/11
450 × 7/2 = 1575/1
r03=02 r05=02 r07=01
1575 × 385/13 = 606375/13
1575 × 13/21 = 975/1
r03=01 r05=02 r13=01
975 × 385/13 = 28875/1
r03=01 r05=03 r07=01 r11=01
28875 × 385/13 = 11116875/13
28875 × 13/21 = 17875/1
r05=03 r11=01 r13=01
17875 × 385/13 = 529375/1
r05=04 r07=01 r11=02
529375 × 385/13 = 203809375/13
529375 × 13/21 = 983125/3
529375 × 1/7 = 75625/1
r05=04 r11=02
75625 × 385/13 = 29115625/13
75625 × 13/21 = 983125/21
75625 × 1/7 = 75625/7
75625 × 3/11 = 20625/1
r03=01 r05=04 r11=01
20625 × 385/13 = 7940625/13
20625 × 13/21 = 89375/7
20625 × 1/7 = 20625/7
20625 × 3/11 = 5625/1
r03=02 r05=04
5625 × 385/13 = 2165625/13
5625 × 13/21 = 24375/7
5625 × 1/7 = 5625/7
5625 × 3/11 = 16875/11
5625 × 7/2 = 39375/2
5625 × 1/3 = 1875/1
r03=01 r05=04
1875 × 385/13 = 721875/13
1875 × 13/21 = 8125/7
1875 × 1/7 = 1875/7
1875 × 3/11 = 5625/11
1875 × 7/2 = 13125/2
1875 × 1/3 = 625/1
r05=04
625 × 385/13 = 240625/13
625 × 13/21 = 8125/21
625 × 1/7 = 625/7
625 × 3/11 = 1875/11
625 × 7/2 = 4375/2
625 × 1/3 = 625/3
r05=04