Running in Printf

You may or may not know, but printf is a Turing-complete language, once you exploit all the strange and wonderful format characters in it (especially %n). But who has time to write code as printf modifiers? Now, thanks to [sebsite], you can at least write in a slightly higher level assembly language and compile to printf. Practical? No. Cool? Undeniably.

As an example, the page shows fizzbuzz written in the assembler:

<pre><code>alias i, fizz, buzz

->fizz ([i] + 1) % 3 == 0
->buzz ([i] + 1) % 5 == 0
->i [i] + 1
->exit [i] == 100

[i] if !![i] & ![fizz] & ![buzz]
"Fizz" if [fizz]
"Buzz" if [buzz]
"\n" if [i]</code></pre>
<pre>

The alias keyword defines constants and, owing to default values, sets i to zero, fizz to one, and buzz to 2. The “arrow” statements store a result into a variable (so the first assignment sets the resulting value into fizz).

You need C23 to compile the assembler. Good luck trying to decode the output.

The printf function can even play tic-tac-toe. If you think considering printf as Turing-complete is weird, we wouldn’t disagree. But we also think it isn’t the weirdest thing we’ve seen, either.



from Blog – Hackaday https://ift.tt/SQsDvTR

Comments

Popular posts from this blog

Modern Radio Receiver Architecture: From Regenerative to Direct Conversion

Build this Cyberdeck in a Cave with a Box of Scraps

Join the Movement with this Mini Cyberdeck