Skip to content(if available)orjump to list(if available)

Show HN: Compile C to Not Gates

Show HN: Compile C to Not Gates

36 comments

·January 17, 2025

Hi! I've been working on the flipjump project, a programming language with 1 opcode: flip (invert) a bit, then jump (unconditionally). So a bit-flip followed by more bit-flips. It's effectively a bunch of NOT gates. This language, as poor as it sounds, is RICH.

Today I completed my compiler from C to FlipJump. It takes C files, and compiles them into flipjump. I finished testing it all today, and it works! My key interest in this project is to stretch what we know of computing and to prove that anything can be done even with minimal power.

I appreciate you reading my announcement, and be happy to answer questions.

More links:

- The flipjump language: https://github.com/tomhea/flip-jump https://esolangs.org/wiki/FlipJump

- c2fj python package https://pypi.org/project/c2fj/

bangaladore

Reminds me of movfuscator [1]. This can compile programs to movs and only movs.

[1] https://github.com/Battelle/movfuscator

beng-nl

Agreed that is a fine piece of work. But the author is Chris Domas. Which is plain from the repo readme, but it’d be clearer to link to his repo.

LPisGood

Battelle is great. They also created some software called Cantor Dust [1] that turns files into images to allow humans to easily spot obfuscated data or files.

The sad thing about this kind of work, because I love it, is that to get paid to do it you need clearances and polygraphs and periodic reinvestigations/continuous monitoring and all sorts of things that I find unpleasant.

[1] https://github.com/Battelle/cantordust

mmastrac

I'm not sure what you mean but I was a security researcher for a large company for a bit and required none of that. I was required to work airgapped at home, however.

LPisGood

Really? You were doing offensive security work not for a government (/contractor)? What sorts companies, aside from some enterprise pen testers, employ these roles?

tonetegeatinst

Looking forward to the poor security researcher who gets to reverse engineer some malware sample they compiles this into for obfuscation... Its going to be an interesting blog post.

tromp

Am I right in deducing that this language gets its power from self-modifying code? I.e. flipping bits within addresses of the opcodes of the running program?

tomhee

You are indeed right

tromp

I would have expected the language documentation to focus more on this observation and to explain for instance how self modification is used to implement while loops. But I don't even see the term mentioned anywhere?!

tomhee

Good point! It's mentioned in the github wiki here: https://github.com/tomhea/flip-jump/wiki/Learn-FlipJump#memo...

It was once in the Readme but as I kept developing it more it become longer and longer, so I moved it into the wiki, and especially to here: https://esolangs.org/wiki/FlipJump

pizza

Ah interesting.. wonder if you can model this with a recursively expanded algebraic expression. I've been thinking lately along similar lines about polynomials that encode pushdown automata, so this is cool to see.

tomhee

If you have an answer I'd be happy to hear it!

jkrshnmenon

I wonder if someone has already made a Reverse Engineering CTF challenge for this concept.

og2023

I read it as reverse engineering WTF challenge... cool stuff though, seriously.

tomhee

jkrshnmenon

I would also be very curious to see if it's possible to make a decompiler for this type of obfuscated program.

tomhee

There is also a brainfuck to flipjump compiler: https://github.com/tomhea/bf2fj

david-gpu

Ah, the convenience of brainfuck with the performance of flip jump. Excellent.

tomhee

By the way, as a challenge, try how you can program an "If" statement in Flipjump.

null

[deleted]

dlcarrier

Maxim (now owned by Analog) actually manufactures a single-instruction processor series, called MAXQ. It uses a single move instruction, with a flag for literals, and a transport triggered architecture.

jumploops

AND, OR, NOT - pick 2

sroussey

NOR - pick 1

platz

How is a jump realized by Not Gates?

tomhee

I dont think that the jump can be realized by NOT gates, but it's essentially "where to find the next NOT command". The jump is indeed a crucial part of the language, as it allows going back, and especially to make self-modifying code.

Jerrrry

I'm guessing by not jumping into a terminating/ halting NOOP.

The logic is within the branching.

artemonster

Id appreciate more explanations from the power of combined bitflip & goto

tomhee

Sure!

https://github.com/tomhea/flip-jump/wiki/Learn-FlipJump

This will let you understand how to implement the very basic "if" in flipjump.

I tried to make it as easy for newcomers, but please feel free and update me if something is written complicated.

After you understand up to the macros, you can try yourself to understand the xor macro, which most of the library is built based on it: https://github.com/tomhea/flip-jump/blob/fe51448932e78db7d76...