Added arithmetics operations, updated readme
This commit is contained in:
parent
0e5fa6c854
commit
f40633f4f1
@ -1,6 +1,12 @@
|
|||||||
# stack_vm
|
# stack_vm
|
||||||
|
|
||||||
Stack based virtual machine
|
Stack based virtual machine and assembly code compiler
|
||||||
|
|
||||||
|
## Features
|
||||||
|
|
||||||
|
- Assembly
|
||||||
|
- Stack operations (push & pop)
|
||||||
|
- Arithmetics operations
|
||||||
|
|
||||||
## TODO
|
## TODO
|
||||||
|
|
||||||
|
@ -3,4 +3,9 @@
|
|||||||
cmd_desc_t cmd_desc[] = {
|
cmd_desc_t cmd_desc[] = {
|
||||||
{PUSH, 1, "PUSH"},
|
{PUSH, 1, "PUSH"},
|
||||||
{POP, 0, "POP"},
|
{POP, 0, "POP"},
|
||||||
|
{ADD, 0, "ADD"},
|
||||||
|
{SUB, 0, "SUB"},
|
||||||
|
{MUL, 0, "MUL"},
|
||||||
|
{DIV, 0, "DIV"},
|
||||||
|
{MOD, 0, "MOD"},
|
||||||
{NONE, 0, "NONE"}}
|
{NONE, 0, "NONE"}}
|
||||||
|
@ -5,6 +5,11 @@ enum command_e
|
|||||||
{
|
{
|
||||||
PUSH,
|
PUSH,
|
||||||
POP,
|
POP,
|
||||||
|
ADD,
|
||||||
|
SUB,
|
||||||
|
MUL,
|
||||||
|
DIV,
|
||||||
|
MOD,
|
||||||
NONE
|
NONE
|
||||||
};
|
};
|
||||||
|
|
||||||
|
40
run.c
40
run.c
@ -25,6 +25,46 @@ int exec(command_t cmd, stack_t *stack)
|
|||||||
case POP:
|
case POP:
|
||||||
stack_pop(stack);
|
stack_pop(stack);
|
||||||
break;
|
break;
|
||||||
|
case ADD:
|
||||||
|
{
|
||||||
|
int b = stack_pop(stack);
|
||||||
|
int a = stack_pop(stack);
|
||||||
|
|
||||||
|
stack_push(stack, a + b);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case SUB:
|
||||||
|
{
|
||||||
|
int b = stack_pop(stack);
|
||||||
|
int a = stack_pop(stack);
|
||||||
|
|
||||||
|
stack_push(stack, a - b);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case MUL:
|
||||||
|
{
|
||||||
|
int b = stack_pop(stack);
|
||||||
|
int a = stack_pop(stack);
|
||||||
|
|
||||||
|
stack_push(stack, a * b);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case DIV:
|
||||||
|
{
|
||||||
|
int b = stack_pop(stack);
|
||||||
|
int a = stack_pop(stack);
|
||||||
|
|
||||||
|
stack_push(stack, a / b);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case MOD:
|
||||||
|
{
|
||||||
|
int b = stack_pop(stack);
|
||||||
|
int a = stack_pop(stack);
|
||||||
|
|
||||||
|
stack_push(stack, a % b);
|
||||||
|
}
|
||||||
|
break;
|
||||||
case NONE:
|
case NONE:
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user