Added single character output
This commit is contained in:
parent
027f16d72b
commit
80931f9b73
@ -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
|
||||
|
@ -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"}};
|
||||
|
||||
|
@ -16,7 +16,8 @@ enum command_e
|
||||
MOD,
|
||||
#ifdef IO_OPERATIONS
|
||||
IN,
|
||||
OUT,
|
||||
OUTS,
|
||||
OUTC,
|
||||
#endif
|
||||
NONE
|
||||
};
|
||||
|
14
src/run.c
14
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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user