Skip to content

Instantly share code, notes, and snippets.

@DutchGhost
Created May 16, 2023 19:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DutchGhost/08437f201ada7bcb2e28be21106a0ac4 to your computer and use it in GitHub Desktop.
Save DutchGhost/08437f201ada7bcb2e28be21106a0ac4 to your computer and use it in GitHub Desktop.
goto!
#include <stdio.h>
int main() {
void *instructions[5];
int ip = 0;
int n = 0;
int a, b;
a = 10;
b = 20;
instructions[0] = &&add;
instructions[1] = &&add;
instructions[2] = &&add;
instructions[3] = &&mul;
instructions[4] = &&hlt;
goto* instructions[ip++];
add:
a = a + b;
printf("add a = %d, b = %d\n", a, b);
goto* instructions[ip++];
sub:
a = a - b;
printf("sub a = %d, b = %d\n", a, b);
goto* instructions[ip++];
mul:
a = a * b;
printf("mul a = %d, b = %d\n", a, b);
goto* instructions[ip++];
div:
a = a / b;
printf("div a = %d, b = %d\n", a, b);
goto* instructions[ip++];
hlt:
goto finish;
finish:
printf("a = %d, b = %d", a, b);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment