Added single character output

This commit is contained in:
Dmitriy Shishkov 2021-04-17 18:32:52 +05:00
parent 027f16d72b
commit 80931f9b73
No known key found for this signature in database
GPG Key ID: 7CAE12ED13853CAC
4 changed files with 22 additions and 6 deletions

View File

@ -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

View File

@ -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"}};

View File

@ -16,7 +16,8 @@ enum command_e
MOD,
#ifdef IO_OPERATIONS
IN,
OUT,
OUTS,
OUTC,
#endif
NONE
};

View File

@ -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;