Added assembly documentation

This commit is contained in:
Dmitriy Shishkov 2021-04-16 21:28:06 +05:00
parent 8dee74c3d0
commit d7c038066c
No known key found for this signature in database
GPG Key ID: 7CAE12ED13853CAC
2 changed files with 45 additions and 0 deletions

View File

@ -8,6 +8,27 @@ Stack based virtual machine and assembly code compiler
- Stack operations (push & pop)
- 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
- VM running

24
run.c
View File

@ -21,8 +21,14 @@ int exec(command_t cmd, stack_t *stack)
switch (cmd.code)
{
/**
* Doesn't do anything
*/
case NONE:
break;
/**
* Pushes value to stack
*/
case PUSH:
{
stack_push(stack, cmd.args[0], res);
@ -31,6 +37,9 @@ int exec(command_t cmd, stack_t *stack)
return *res;
}
break;
/**
* Removes from stack top
*/
case POP:
{
stack_pop(stack, res);
@ -39,6 +48,9 @@ int exec(command_t cmd, stack_t *stack)
return *res;
}
break;
/**
* Removes two top values in stack and pushes their sum
*/
case ADD:
{
int b = stack_pop(stack, res);
@ -51,6 +63,9 @@ int exec(command_t cmd, stack_t *stack)
return *res;
}
break;
/**
* Removes two top values in stack and pushes substraction of them
*/
case SUB:
{
int b = stack_pop(stack, res);
@ -63,6 +78,9 @@ int exec(command_t cmd, stack_t *stack)
return *res;
}
break;
/**
* Removes two top values in stack and pushes multiplication of them
*/
case MUL:
{
int b = stack_pop(stack, res);
@ -75,6 +93,9 @@ int exec(command_t cmd, stack_t *stack)
return *res;
}
break;
/**
* Removes two top values in stack and pushes integer part of division
*/
case DIV:
{
int b = stack_pop(stack, res);
@ -87,6 +108,9 @@ int exec(command_t cmd, stack_t *stack)
return *res;
}
break;
/**
* Removes two top values in stack and pushes modulo
*/
case MOD:
{
int b = stack_pop(stack, res);