# Fibonacci using terminfo's native integer addition, traced on stdout. # # export TERMINFO="$PWD"; tic fib.txt; yes 'cup 0 0' | head -n 10 | TERM=fib tput -S # # Registers: # A = F(N-1) # B = F(N) # N = current Fibonacci index, step counter and initialized flag # # if (N == 0) { # A = 0; B = 1; N = 1; // init # } else { # stack: B' = A + B, A' = old B; N = N + 1; // compute next value # } # print trace line fib,cup= %?%gN%{0}%=%t%{0}%PA%{1}%PB%{1}%PN %e%gA%gB%+%gB%PA%PB%gN%{1}%+%PN%; A=%gA%d B=%gB%d N=%gN%d F(%gN%d)=%gB%d\r\n,