{"id":22041943,"url":"https://github.com/cdayz/simple_lang","last_synced_at":"2025-05-08T00:53:28.688Z","repository":{"id":54243000,"uuid":"195462462","full_name":"Cdayz/simple_lang","owner":"Cdayz","description":"Simple Python implementation of ASM-like language on virtual machine","archived":false,"fork":false,"pushed_at":"2019-07-08T16:17:14.000Z","size":83,"stargazers_count":5,"open_issues_count":0,"forks_count":2,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-05-08T00:53:23.240Z","etag":null,"topics":["asm","asm-like","interpreter","simple-programming-language","virtual-machine"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Cdayz.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-07-05T20:11:48.000Z","updated_at":"2023-03-27T19:27:04.000Z","dependencies_parsed_at":"2022-08-13T09:50:49.211Z","dependency_job_id":null,"html_url":"https://github.com/Cdayz/simple_lang","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/Cdayz%2Fsimple_lang","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Cdayz%2Fsimple_lang/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Cdayz%2Fsimple_lang/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Cdayz%2Fsimple_lang/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Cdayz","download_url":"https://codeload.github.com/Cdayz/simple_lang/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252978729,"owners_count":21834914,"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":["asm","asm-like","interpreter","simple-programming-language","virtual-machine"],"created_at":"2024-11-30T12:10:38.704Z","updated_at":"2025-05-08T00:53:28.670Z","avatar_url":"https://github.com/Cdayz.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Build Status](https://travis-ci.org/Cdayz/simple_lang.svg?branch=master)](https://travis-ci.org/Cdayz/simple_lang) [![codecov](https://codecov.io/gh/Cdayz/simple_lang/branch/master/graph/badge.svg)](https://codecov.io/gh/Cdayz/simple_lang)\n\n# Simple Lang Specification\n\nSimpleLang is a subset of assembler languages implemented in virtual machine\n\n## Language Specification\n\n### Registers\n\nIn SimpleLang we have only 4 General-Purpose registers `r1, r2, r3, r4`.\nOne accumulator register `A` and 4 conditional registers `EQ`, `GT`, `LT`, `NE`\n\n### Operations\n\nIn SimpleLang only that operations is allowed and implemented:\n\n1) `MOV (r|a), (r|a)` - store in first operand value from second operand\n2) `MOV (r|a), @r` - store in first operand value by address in second operand\n3) `ADD A, r` - add value from second operand to accumulator\n4) `DIV A, r` - divide value from accumulator by value in second operand\n(Note: Only integer division is allowe and implemented)\n5) `SUB A, r` - substract accumulator by value of second operand\n6) `MUL A, r` - multiply accumulator by value of second operand\n7) `LABEL lbl` - make that lbl points to that line of code\n8) `JMP lbl` - jump to line that lbl points\n9) `CMP A, r` - compare value of accumulator with second operand and set specific registers\n10) `JMP_EQ, JMP_LT, JMP_GT, JMP_NE` - conditional jumps\n11) `AND, OR, XOR, NOT` - bit operations\n12) `PRINT (@|)(A|r|num)` - print value of register or memory by reg.pointer to stdout\n13) `INPUT (@|)(A|r)` - read ONE NUMBER from stdin and write to register or to memory point\n14) `CALL lbl` - call subroutine under label lbl\n15) `RET` - return from subroutine (Only one subroutine can be called at the monent)\n\n\n### Bytecode structure\n\nOperation bytecode:\n```\n| 2 byte  | 1 byte | 4 byte | 1 byte | 4 byte |\n| op_code | arg_ty | op_arg | arg_ty | op_arg |\n```\n\none operation will be encoded to (2+1+4+1+4) = 12 byte\n\nif operation doesn't have any of arguments pad_sym will be used\nand arg_type will be set as pad_symbol!\n\n1 byte before every argument is placeholder for argument type\n(e.g. reference, register or in-place value)\n\n4 byte arguments size needed for in-place values\nIn-place values is a 32-bit integers only!\n\n\n### Bytecode invalidation\n\nEvery bytecode file have one metadata section before real code\n\n#### Metadata section structure\n```\n|    2 byte    | 4 byte |\n|magical number|   crc  |\n```\nCRC sum is used for code invalidation.\n\n\n### Code examples\n\nCalculate N-th fibonacci number\n\n```\nLABEL MAIN\n    INPUT r1\n    CALL FIBONACCI\n    PRINT r2\n    END\n\nLABEL FIBONACCI\n    ; Prepare fibonacci\n    MOV r2, 0\n    MOV r3, 1\n\n    LABEL FIBONACCI_LOOP\n        ; Calculate n fibonacci number\n        ; Store result at r2\n\n        MOV A, r2\n        ADD A, r3\n\n        MOV r2, r3\n        MOV r3, A\n\n        SUB r1, 1\n\n        ; Loop while r1 != 0\n        CMP r1, 0\n        JMP_GT FIBONACCI_LOOP\n\n    RET\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcdayz%2Fsimple_lang","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcdayz%2Fsimple_lang","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcdayz%2Fsimple_lang/lists"}