{"id":20063773,"url":"https://github.com/hiperiondev/sm1vm","last_synced_at":"2025-03-02T10:27:46.205Z","repository":{"id":112267791,"uuid":"129316316","full_name":"hiperiondev/SM1vm","owner":"hiperiondev","description":"Tiny embeddable Stack Machine / Forth Machine","archived":false,"fork":false,"pushed_at":"2023-04-16T23:06:04.000Z","size":266,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-12T22:43:06.772Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hiperiondev.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-04-12T22:08:22.000Z","updated_at":"2023-04-16T22:33:59.000Z","dependencies_parsed_at":"2023-05-12T07:45:27.765Z","dependency_job_id":null,"html_url":"https://github.com/hiperiondev/SM1vm","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hiperiondev%2FSM1vm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hiperiondev%2FSM1vm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hiperiondev%2FSM1vm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hiperiondev%2FSM1vm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hiperiondev","download_url":"https://codeload.github.com/hiperiondev/SM1vm/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241491778,"owners_count":19971555,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-13T13:43:47.082Z","updated_at":"2025-03-02T10:27:46.182Z","avatar_url":"https://github.com/hiperiondev.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":" [![License](https://img.shields.io/badge/licence-GPLv3-blue.svg?style=flat)](https://github.com/hiperiondev/SM1vm/blob/master/LICENSE) [![Version](https://img.shields.io/badge/version-v1.0-blue.svg)](https://github.com/hiperiondev/SM1vm/)\n# SM1vm\n **Tiny embeddable Stack Machine / Forth Machine**\n\nThis project is based on H2 VM but modified for to be more flexible and embeddable, especially on constrained microcontrollers.\n\n## About\nThe project is based on a self-contained library that provides everything necessary to embed the VM (SM1.h).  \n\nThe 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.\n\nIt is possible to build the VM as a library to be used in other projects. As an example see: \u003chttps://github.com/hiperiondev/SM1vm-Gambas3\u003e\n\nAlso have a very simple assembler and disassembler.\n\nMany 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).\n  \nThese conditional functions are:  \n```\n#define DEBUG  \n    DEBUG information printing  \n#define UNDER_OVER  \n    Add control on OVERFLOW and UNDERFLOW of stack pointers and PC  \n#define CARRY  \n    EXPERIMENTAL: Adds CARRY functions in the addition, subtraction, multiplication and division primitives  \n#define EXTBITS  \n    EXPERIMENTAL: Uses the -2 bits of the delta of the stack pointers for added functions\n```\n\n## Instruction Encoding\n```\n        +---------------------------------------------------------------+\n        | F | E | D | C | B | A | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |\n        +---------------------------------------------------------------+\n        | 1 |                    LITERAL VALUE                          |\n        +---------------------------------------------------------------+\n        | 0 | 0 | 0 | i |        BRANCH TARGET ADDRESS                  |\n        +---------------------------------------------------------------+\n        | 0 | 0 | 1 | i |        CONDITIONAL BRANCH TARGET ADDRESS      |\n        +--------------------------------------------------------------+\n        | 0 | 1 | 0 | i |        CALL TARGET ADDRESS                    |\n        +---------------------------------------------------------------+\n        | 0 | 1 | 1 |   ALU OPERATION   |T2N|T2R|N2T|R2P| RSTACK| DSTACK|\n        +---------------------------------------------------------------+\n        | F | E | D | C | B | A | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |\n        +---------------------------------------------------------------+\n\n        T   : Top of data stack\n        N   : Next on data stack\n        PC  : Program Counter\n\n        i : indirect from register\n\n        LITERAL VALUES : push a value onto the data stack\n        CONDITIONAL    : BRANCHS pop and test the T\n        CALLS          : PC+1 onto the return stack\n\n        T2N : Move T to N\n        T2R : Move T to top of return stack\n        N2T : Move the new value of T (or D) to N\n        R2P : Move top of return stack to PC\n\n        RSTACK and DSTACK :\n        00 = 0\n        01 = +1\n        10 = -1\n        11 = -2 or\n             extended bit (not modify stack pointers. used for alu extended operations)\n             (depend on compilation flag EXTBITS)\n```\n\n## Instruction Set\n```\n### BRANCH / LITERAL\n JMP: jump\n JMZ: jump if zero\n CLL: call\n LIT: literal\n\n### ALU INSTRUCTIONS\n TOP: t (ALU_EX == 1 : t++)\n SCN: n\n TRS: top of return stack\n GET: load from address t\n PUT: store n to address t\n DPL: double cell addition\n DML: double cell multiply\n AND: bitwise and\n BOR: bitwise or\n XOR: bitwise xor\n NOT: bitwise inversion\n DEC: decrement\n EQ0: equal to zero\n EQU: equality test\n UCP: unsigned comparison (n-t)\n CMP: signed comparison (n\u003ct)\n RSH: logical right shift\n LSH: logical left shift\n GSP: depth of data stack\n GRS: depth of return stack\n SSP: set data stack depth\n SRP: set return stack depth\n REG: get register t (status t == 0xff)\n SRG: set n on register t (status t == 0xff)\n UMD: u/mod\n MOD: /mod\n NXT: compare top and 2nd element of return stack and put comparison to t. If not eq increment 2nd else drop top and 2nd\n GPC: PC to t\n EXF: execute external function\n LOD: load from stack position (from bottom)\n STR: store to stack position (from bottom)\n MOV: copy register t to register n\n \n### ALU MODIFIERS\n T2N: move t to n\n T2R: move t to r\n N2T: move n to t\n R2P: move r to pc\n\n### ALU DELTA\n d+1: dp + 1\n d-1: dp - 1\n d-2: dp - 2 (or extended bit) \n r+1: rp + 1\n r-1: rp - 1\n r-2: rp - 2 (or extended bit)\n```\n\n## Assembler\n The assembler accept these directives:\n```\n    .equ: Assigns a value to a label.\n  .macro: Start of a macro. Takes the name as parameter.\n          When the name of the macro is written later in the program, \n          the macro definition is expanded at the place it was used. \n   .endm: End of a macro definition.\n.include: Start reading from a specified file.\n   .word: Define new mnemonic from complete line. Ex. dup@ get t2n d+1\n  .label: Assign the address at this point to label.\n.comment: Comment line.\n    .org: Set the location counter to an absolute value. Only accept decimal number. \n   .data: Insert uint_16 value. \n .string: Insert string text.\n```\nNOTE 1: Directives can't be used inside macro.\nNOTE 2: Value $HERE$ represent actual address pointer, can be \n        offsetted ex: .equ label $HERE + 3\n\n## Usage example\n```\nSM1 [-d|-a] file.in [file.out] [basewords] [ramSize]\n```\n\n_For more examples and usage, please refer to the [Wiki][wiki]._\n\n## Development setup\n\n[TODO]\n```sh\n[TODO]\n```\n## Architecture and design\n[TODO]\n## Release History\n\n* 1.0\n    * [TODO]\n\n## Contributing\n\n1. Fork it (\u003chttps://github.com/hiperiondev/SM1vm/fork\u003e)\n2. Create your feature branch (`git checkout -b feature/fooBar`)\n3. Commit your changes (`git commit -am 'Add some fooBar'`)\n4. Push to the branch (`git push origin feature/fooBar`)\n5. Create a new Pull Request\n\n\u003c!-- Markdown link \u0026 img dfn's --\u003e\n[wiki]:https://github.com/hiperiondev/SM1vm/wiki/%5B1%5D-SM1vm:-Tiny-embeddable-Stack-Machine---Forth-Machine\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhiperiondev%2Fsm1vm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhiperiondev%2Fsm1vm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhiperiondev%2Fsm1vm/lists"}