https://github.com/hiperiondev/sm1vm
Tiny embeddable Stack Machine / Forth Machine
https://github.com/hiperiondev/sm1vm
Last synced: over 1 year ago
JSON representation
Tiny embeddable Stack Machine / Forth Machine
- Host: GitHub
- URL: https://github.com/hiperiondev/sm1vm
- Owner: hiperiondev
- License: gpl-3.0
- Created: 2018-04-12T22:08:22.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2023-04-16T23:06:04.000Z (about 3 years ago)
- Last Synced: 2025-01-12T22:43:06.772Z (over 1 year ago)
- Language: C
- Homepage:
- Size: 260 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://github.com/hiperiondev/SM1vm/blob/master/LICENSE) [](https://github.com/hiperiondev/SM1vm/)
# SM1vm
**Tiny embeddable Stack Machine / Forth Machine**
This project is based on H2 VM but modified for to be more flexible and embeddable, especially on constrained microcontrollers.
## About
The project is based on a self-contained library that provides everything necessary to embed the VM (SM1.h).
The only exception is the memory access functions (sm1_mem_put and sm1_mem_get) which must be defined by the user. This allows adaptation to the local implementation access to the program memory, both in hardware and in logic.
It is possible to build the VM as a library to be used in other projects. As an example see:
Also have a very simple assembler and disassembler.
Many functionalities are defined at the time of compilation, allowing to size the machine according to its use as well as the debug (not necessary in the final implementation).
These conditional functions are:
```
#define DEBUG
DEBUG information printing
#define UNDER_OVER
Add control on OVERFLOW and UNDERFLOW of stack pointers and PC
#define CARRY
EXPERIMENTAL: Adds CARRY functions in the addition, subtraction, multiplication and division primitives
#define EXTBITS
EXPERIMENTAL: Uses the -2 bits of the delta of the stack pointers for added functions
```
## Instruction Encoding
```
+---------------------------------------------------------------+
| F | E | D | C | B | A | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
+---------------------------------------------------------------+
| 1 | LITERAL VALUE |
+---------------------------------------------------------------+
| 0 | 0 | 0 | i | BRANCH TARGET ADDRESS |
+---------------------------------------------------------------+
| 0 | 0 | 1 | i | CONDITIONAL BRANCH TARGET ADDRESS |
+--------------------------------------------------------------+
| 0 | 1 | 0 | i | CALL TARGET ADDRESS |
+---------------------------------------------------------------+
| 0 | 1 | 1 | ALU OPERATION |T2N|T2R|N2T|R2P| RSTACK| DSTACK|
+---------------------------------------------------------------+
| F | E | D | C | B | A | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
+---------------------------------------------------------------+
T : Top of data stack
N : Next on data stack
PC : Program Counter
i : indirect from register
LITERAL VALUES : push a value onto the data stack
CONDITIONAL : BRANCHS pop and test the T
CALLS : PC+1 onto the return stack
T2N : Move T to N
T2R : Move T to top of return stack
N2T : Move the new value of T (or D) to N
R2P : Move top of return stack to PC
RSTACK and DSTACK :
00 = 0
01 = +1
10 = -1
11 = -2 or
extended bit (not modify stack pointers. used for alu extended operations)
(depend on compilation flag EXTBITS)
```
## Instruction Set
```
### BRANCH / LITERAL
JMP: jump
JMZ: jump if zero
CLL: call
LIT: literal
### ALU INSTRUCTIONS
TOP: t (ALU_EX == 1 : t++)
SCN: n
TRS: top of return stack
GET: load from address t
PUT: store n to address t
DPL: double cell addition
DML: double cell multiply
AND: bitwise and
BOR: bitwise or
XOR: bitwise xor
NOT: bitwise inversion
DEC: decrement
EQ0: equal to zero
EQU: equality test
UCP: unsigned comparison (n-t)
CMP: signed comparison (n)
2. Create your feature branch (`git checkout -b feature/fooBar`)
3. Commit your changes (`git commit -am 'Add some fooBar'`)
4. Push to the branch (`git push origin feature/fooBar`)
5. Create a new Pull Request
[wiki]:https://github.com/hiperiondev/SM1vm/wiki/%5B1%5D-SM1vm:-Tiny-embeddable-Stack-Machine---Forth-Machine