Added assembly documentation
This commit is contained in:
parent
8dee74c3d0
commit
d7c038066c
21
README.md
21
README.md
@ -8,6 +8,27 @@ Stack based virtual machine and assembly code compiler
|
|||||||
- Stack operations (push & pop)
|
- Stack operations (push & pop)
|
||||||
- Arithmetics operations
|
- 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
|
## TODO
|
||||||
|
|
||||||
- VM running
|
- VM running
|
||||||
|
24
run.c
24
run.c
@ -21,8 +21,14 @@ int exec(command_t cmd, stack_t *stack)
|
|||||||
|
|
||||||
switch (cmd.code)
|
switch (cmd.code)
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Doesn't do anything
|
||||||
|
*/
|
||||||
case NONE:
|
case NONE:
|
||||||
break;
|
break;
|
||||||
|
/**
|
||||||
|
* Pushes value to stack
|
||||||
|
*/
|
||||||
case PUSH:
|
case PUSH:
|
||||||
{
|
{
|
||||||
stack_push(stack, cmd.args[0], res);
|
stack_push(stack, cmd.args[0], res);
|
||||||
@ -31,6 +37,9 @@ int exec(command_t cmd, stack_t *stack)
|
|||||||
return *res;
|
return *res;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
/**
|
||||||
|
* Removes from stack top
|
||||||
|
*/
|
||||||
case POP:
|
case POP:
|
||||||
{
|
{
|
||||||
stack_pop(stack, res);
|
stack_pop(stack, res);
|
||||||
@ -39,6 +48,9 @@ int exec(command_t cmd, stack_t *stack)
|
|||||||
return *res;
|
return *res;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
/**
|
||||||
|
* Removes two top values in stack and pushes their sum
|
||||||
|
*/
|
||||||
case ADD:
|
case ADD:
|
||||||
{
|
{
|
||||||
int b = stack_pop(stack, res);
|
int b = stack_pop(stack, res);
|
||||||
@ -51,6 +63,9 @@ int exec(command_t cmd, stack_t *stack)
|
|||||||
return *res;
|
return *res;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
/**
|
||||||
|
* Removes two top values in stack and pushes substraction of them
|
||||||
|
*/
|
||||||
case SUB:
|
case SUB:
|
||||||
{
|
{
|
||||||
int b = stack_pop(stack, res);
|
int b = stack_pop(stack, res);
|
||||||
@ -63,6 +78,9 @@ int exec(command_t cmd, stack_t *stack)
|
|||||||
return *res;
|
return *res;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
/**
|
||||||
|
* Removes two top values in stack and pushes multiplication of them
|
||||||
|
*/
|
||||||
case MUL:
|
case MUL:
|
||||||
{
|
{
|
||||||
int b = stack_pop(stack, res);
|
int b = stack_pop(stack, res);
|
||||||
@ -75,6 +93,9 @@ int exec(command_t cmd, stack_t *stack)
|
|||||||
return *res;
|
return *res;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
/**
|
||||||
|
* Removes two top values in stack and pushes integer part of division
|
||||||
|
*/
|
||||||
case DIV:
|
case DIV:
|
||||||
{
|
{
|
||||||
int b = stack_pop(stack, res);
|
int b = stack_pop(stack, res);
|
||||||
@ -87,6 +108,9 @@ int exec(command_t cmd, stack_t *stack)
|
|||||||
return *res;
|
return *res;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
/**
|
||||||
|
* Removes two top values in stack and pushes modulo
|
||||||
|
*/
|
||||||
case MOD:
|
case MOD:
|
||||||
{
|
{
|
||||||
int b = stack_pop(stack, res);
|
int b = stack_pop(stack, res);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user