Created
May 16, 2023 19:57
-
-
Save DutchGhost/08437f201ada7bcb2e28be21106a0ac4 to your computer and use it in GitHub Desktop.
goto!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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