From d7c038066c92b9183b762b16d0f927920589f574 Mon Sep 17 00:00:00 2001 From: dm1sh Date: Fri, 16 Apr 2021 21:28:06 +0500 Subject: [PATCH] Added assembly documentation --- README.md | 21 +++++++++++++++++++++ run.c | 24 ++++++++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/README.md b/README.md index 19fc5a5..5120fc0 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,27 @@ Stack based virtual machine and assembly code compiler - Stack operations (push & pop) - Arithmetics operations +## Assembly documentation + +### Commands: + +- **NONE** + Doesn't do anything +- **PUSH** + Pushes value to stack +- **POP** + Removes from stack top +- **ADD** + Removes two top values in stack and pushes their sum +- **SUB** + Removes two top values in stack and pushes substraction of them +- **MUL** + Removes two top values in stack and pushes multiplication of them +- **DIV** + Removes two top values in stack and pushes integer part of division +- **MOD** + Removes two top values in stack and pushes modulo + ## TODO - VM running diff --git a/run.c b/run.c index 8aab562..90d400a 100644 --- a/run.c +++ b/run.c @@ -21,8 +21,14 @@ int exec(command_t cmd, stack_t *stack) switch (cmd.code) { + /** + * Doesn't do anything + */ case NONE: break; + /** + * Pushes value to stack + */ case PUSH: { stack_push(stack, cmd.args[0], res); @@ -31,6 +37,9 @@ int exec(command_t cmd, stack_t *stack) return *res; } break; + /** + * Removes from stack top + */ case POP: { stack_pop(stack, res); @@ -39,6 +48,9 @@ int exec(command_t cmd, stack_t *stack) return *res; } break; + /** + * Removes two top values in stack and pushes their sum + */ case ADD: { int b = stack_pop(stack, res); @@ -51,6 +63,9 @@ int exec(command_t cmd, stack_t *stack) return *res; } break; + /** + * Removes two top values in stack and pushes substraction of them + */ case SUB: { int b = stack_pop(stack, res); @@ -63,6 +78,9 @@ int exec(command_t cmd, stack_t *stack) return *res; } break; + /** + * Removes two top values in stack and pushes multiplication of them + */ case MUL: { int b = stack_pop(stack, res); @@ -75,6 +93,9 @@ int exec(command_t cmd, stack_t *stack) return *res; } break; + /** + * Removes two top values in stack and pushes integer part of division + */ case DIV: { int b = stack_pop(stack, res); @@ -87,6 +108,9 @@ int exec(command_t cmd, stack_t *stack) return *res; } break; + /** + * Removes two top values in stack and pushes modulo + */ case MOD: { int b = stack_pop(stack, res);