Skip to content

Instantly share code, notes, and snippets.

@rexim
Last active March 10, 2021 12:09
Show Gist options
  • Save rexim/31b5100ef86eee736b383d09b6b14591 to your computer and use it in GitHub Desktop.
Save rexim/31b5100ef86eee736b383d09b6b14591 to your computer and use it in GitHub Desktop.
Quick Gist of the paradox we are trying to prevent in our assembly

The "If-Label" Paradox

In our assembly we are implementing the support for conditional translation:

%include "natives.hasm"
%const N 10
main:
    push 1
    push 2
    push 3
    %if N < 69
        drop
        drop
        drop
    %end
    halt

If N < 69 is true the block of 3 drop-s will be included in the final executable, otherwise it will not.

The problem occurs when we have the following situation:

%include "natives.hasm"
%const N 10
main:
    push 1
    push 2
    push 3
    %if end < 69
        drop
        drop
        drop
    %end
end:
    halt

The condition depends on the value of end, but the value of end depends on whether the block above it is included. This creates a paradox that we must detect at translation time and report to the user approriately with hints on how to resolve it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment