diff options
Diffstat (limited to 'comp/work/58')
-rw-r--r-- | comp/work/58/example.c | 54 | ||||
-rw-r--r-- | comp/work/58/libraylib.a | bin | 0 -> 2766972 bytes | |||
-rw-r--r-- | comp/work/58/starter | 27 | ||||
-rw-r--r-- | comp/work/58/test.s | 35 |
4 files changed, 116 insertions, 0 deletions
diff --git a/comp/work/58/example.c b/comp/work/58/example.c new file mode 100644 index 0000000..1fb81b8 --- /dev/null +++ b/comp/work/58/example.c @@ -0,0 +1,54 @@ +#include <stdio.h> +#include <stdlib.h> + +typedef enum op { + ADD, + SUB, + MUL, + DIV, +} op; + +struct operation { + int a, b; + op o; + int (*funcs[2][2])(int, int); +}; + +int add(int a, int b) { + return a + b; +} +int sub(int a, int b) { + return a - b; +} +int mul(int a, int b) { + return a * b; +} +int Div(int a, int b) { + return a / b; +} + +int runop(struct operation *o) { + switch (o->o) { + case ADD: return o->funcs[0][0](o->a, o->b); + case SUB: return o->funcs[0][1](o->a, o->b); + case MUL: return o->funcs[1][0](o->a, o->b); + case DIV: return o->funcs[1][1](o->a, o->b); + } + return -1; +} + +struct operation *initop(int a, int b, op ope) { + struct operation *o = malloc(sizeof(struct operation)); + o->a = a; + o->b = b; + o->funcs[0][0] = &add; + o->funcs[0][1] = ⊂ + o->funcs[1][0] = &mul; + o->funcs[1][1] = &Div; + o->o = ope; +} + +int main() { + struct operation *o = initop(5, 5, MUL); + printf("%d\n", runop(o)); +} diff --git a/comp/work/58/libraylib.a b/comp/work/58/libraylib.a Binary files differnew file mode 100644 index 0000000..8af9033 --- /dev/null +++ b/comp/work/58/libraylib.a diff --git a/comp/work/58/starter b/comp/work/58/starter new file mode 100644 index 0000000..0261da9 --- /dev/null +++ b/comp/work/58/starter @@ -0,0 +1,27 @@ +130 | R1 | R2 | R3 | R4 + 83 | 83 | 0 | | 0 + | | 1 | 1 | + | | | | 1 + | 41 | | | + | | 2 | 1 | + | | | | 2 + | 20 | | | + | | 3 | 0 | + | 10 | | | + | | 4 | 0 | + | 5 | | | + | | 5 | 1 | 3 + | 2 | | | + | | 6 | 0 | + | 1 | | | + | | 7 | 1 | 4 + | 0 | | | + | 83 | | | 0 + | 211| | | + 211| | | | + +It adds a parity bit to the number + +faster, lower level access + +not OO or functional diff --git a/comp/work/58/test.s b/comp/work/58/test.s new file mode 100644 index 0000000..cbf161f --- /dev/null +++ b/comp/work/58/test.s @@ -0,0 +1,35 @@ +.text +.global _start + +_start: + push %rbp + mov %rsp, %rbp + + mov $100, [rsp - 4] + mov $100, (rsp - 8) + push $name + call InitWindow + + add $16, %rsp + pop %rbp + ret + + mov $0, %r12 +loop: + push %rbp + mov %rsp, %rbp + call WindowShouldClose + pop %rbp + ret + + cmp %r12, %rax + je loop + + push $1 + call exit + +.data +name: +.asciz "testing" + + |