Skip to main content

Practice ยท 2 of 4

Dense Opcodes

Implement the array-of-functions interpreter: ``c /* opcodes 0..3 map to: nop(a,b)=a, add, sub, mul (in that order). run_op returns OPS[code](a, b), or -1 for out-of-range code. */ int run_op(int code, int a, int b); /* validates: 1 iff code in [0,3] */ int op_valid(int code); ``

Difficulty: intermediate

Back to lesson: Practice: Dispatch & Context Gym