From 80931f9b738a72c2685366d0431c698f839f8c24 Mon Sep 17 00:00:00 2001 From: dm1sh Date: Sat, 17 Apr 2021 18:32:52 +0500 Subject: [PATCH] Added single character output --- README.md | 8 +++++--- src/command.c | 3 ++- src/command.h | 3 ++- src/run.c | 14 +++++++++++++- 4 files changed, 22 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 4aec7ce..3d8bd17 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,8 @@ Stack based virtual machine and assembly code compiler ## Features -- Binary code execution (assembly language compilation coming soon) +- Assembly language compilation +- Binary code execution - Assembly - Stack operations (push & pop) - Arithmetics operations @@ -32,12 +33,13 @@ Stack based virtual machine and assembly code compiler Removes two top values in stack and pushes modulo - **IN** Inputs string with C I/O operators -- **OUT** +- **OUTS** Outputs string with C I/O operators +- **OUTC** + Outputs one stack element as char with I/O operators ## TODO -- Assembly compiler - Variables - Arithmetics operators - Strings diff --git a/src/command.c b/src/command.c index dfc9144..58e3b65 100644 --- a/src/command.c +++ b/src/command.c @@ -10,7 +10,8 @@ cmd_desc_t cmd_desc[] = { {MOD, 0, "MOD"}, #ifdef IO_OPERATIONS {IN, 0, "IN"}, - {OUT, 0, "OUT"}, + {OUTS, 0, "OUTS"}, + {OUTC, 0, "OUTC"}, #endif {NONE, 0, "NONE"}}; diff --git a/src/command.h b/src/command.h index 42492c7..45493c5 100644 --- a/src/command.h +++ b/src/command.h @@ -16,7 +16,8 @@ enum command_e MOD, #ifdef IO_OPERATIONS IN, - OUT, + OUTS, + OUTC, #endif NONE }; diff --git a/src/run.c b/src/run.c index f90bbeb..b815516 100644 --- a/src/run.c +++ b/src/run.c @@ -145,7 +145,7 @@ int exec(command_t cmd, stack_t *stack) /** * Outputs string with C I/O operators */ - case OUT: + case OUTS: { char ch = stack_pop(stack, res); if (res != NULL) @@ -160,6 +160,18 @@ int exec(command_t cmd, stack_t *stack) } } break; + /** + * Outputs one stack element as char with I/O operators + */ + case OUTC: + { + char ch = stack_get(stack, stack->cursor, res); + if (res != NULL) + return *res; + + putchar(ch); + } + break; #endif default: return 1;