{"id":23978648,"url":"https://github.com/simmsb/cpu_emulator","last_synced_at":"2025-09-19T11:47:35.960Z","repository":{"id":94007271,"uuid":"73858438","full_name":"simmsb/Cpu_emulator","owner":"simmsb","description":"My version of the little man computer, has support for stack and some other things, also comes with a simple compiler","archived":false,"fork":false,"pushed_at":"2017-06-14T18:41:24.000Z","size":130,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-07T08:19:38.085Z","etag":null,"topics":["compiler","cpu","cpu-emulator","stack"],"latest_commit_sha":null,"homepage":"","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/simmsb.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":"2016-11-15T21:51:37.000Z","updated_at":"2023-01-30T04:56:59.000Z","dependencies_parsed_at":null,"dependency_job_id":"a0543fb8-e8f9-4d9d-a939-708552eec02c","html_url":"https://github.com/simmsb/Cpu_emulator","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/simmsb%2FCpu_emulator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simmsb%2FCpu_emulator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simmsb%2FCpu_emulator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simmsb%2FCpu_emulator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/simmsb","download_url":"https://codeload.github.com/simmsb/Cpu_emulator/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240540554,"owners_count":19817791,"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":["compiler","cpu","cpu-emulator","stack"],"created_at":"2025-01-07T08:19:06.249Z","updated_at":"2025-09-19T11:47:30.903Z","avatar_url":"https://github.com/simmsb.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Cpu_emulator\n\nA python version of the Little man computer\n\nNote: I no longer work on this and am now focusing on a design that is *actually* good [here](https://github.com/nitros12/some_instruction_set)\n\n# Description\n\nThis language is very simple. It has support for arithmetic operations, moving data around, printing integers/ characters to stdout, jumping, conditional jumps and waiting for user input.\n\nIt will automatically identify variables and assign them a place in memory (It is not smart and just groups every variable address at the start of the program, and then adds an unconditional jump at the start to cause the computer to skip the variables). It can also identify jump labels, and will assign any jumps to that location correctly. -- Dont use these\n\n# syntax\nPretty much everything has changed to make some stuff easier.\n\nA plain number is a plain number, use square brackets to deref to a memory location.\nDerefs are parsed so you are capable of doing `[[@acc+[@stk-[@stk+4]]]]` and it will resolve.\nRegisters start with `@` and are accessed with their name directly (for example: `@acc`). The list of registers are:\n\n```\nCUR  \u003c current instruction register (no reason to access directly use jump command to modify).\nACC  \u003c accumulator, arithmetic operations are done to this register.\nRAX  \u003c general purpose register\nEAX  \u003c general purpose register\nRET  \u003c return value from functions (also general purpose)\nCMP  \u003c last comparison register. (unlike the others, this contains a string, dont touch it and you'll be fine)\nSTK  \u003c Stack Pointer\nLSTK \u003c Base pointer\n```\n\n\nWhen using commands that write to a location, the command takes the memory location to write to, or the register to write to.\nTo write to a register, use `@reg` on it's own. to write to a location (even if you use a reg to get to that location) just do so `@reg+offset`\n\n# Okay, Time for the command list\n\n```\nADD \u003cval\u003e  \u003c- adds Contents of register/ inline number/ contents of memory location to @ACC register.\nSUB \u003cval\u003e  \u003c- same as above, but subtracts.\nMUL \u003cval\u003e  \u003c- same as above, but multiplies, Note that because of how python does variable swapping, you can multiply the accumulator by itself.\nDIV \u003cval\u003e\nSET \u003cval\u003e  \u003c- sets the accumulator to an absolute value. (as so that you dont have to reset it) (literally no reason for this to exist when you can use MOV)\nMOV \u003c@/ Memory Location (from)\u003e \u003c@/ Memory Location (to)\u003e  \u003c- moves contents of one location to the other.\nCMP \u003c@/ #/ Value\u003e \u003c@/ #/ Value\u003e  \u003c- compares the first with the second, stores in the @CMP register, if second parameter is not provided, compares with 0 instead.\nJUMP \u003c@/ #/ Value\u003e  \u003c- jump to location\nlje, mje, leje, meje, eqje, nqje \u003c@/ #/ Value\u003e  \u003c- jump to memory location if last comparison is true for [less than, more than, less than or equal, more than or equal, equal, not equal] in that order\nprntint \u003c@/ #/ Value\u003e  \u003c- print value to stdout\nPRNTSTR \u003c@/ #/ Value\u003e  \u003c- print value as a character to stdout (note does not print newline character)\nPRNTNL  \u003c- prints a newline on stdout\nINPUT \u003c@/ Memloc\u003e  \u003c- waits for user input on the command line and saves it into specified location\nHALT  \u003c- computer stops operation\nMOVLOC \u003c@/ Memloc (from)\u003e \u003c@/ Memloc (to)\u003e  \u003c- Moves contents of memory location at location 1 to location 2\nPUSHSTK \u003c@/ #/ Value\u003e  \u003c- push value to stack\nPOPSTK \u003c@/ Memloc\u003e\nCALL \u003cfunction\u003e *\u003c@/ #/ Value\u003e  \u003c- Call function (jump address) with arguments (syntax sugar for pushing onto stack (left to right) then jumping (handles return address for you))\nRET \u003c- Return from current function\n```\n\nLook into the directory: `example programs` for some examples.\n\nPython stuff:\n\n```\nmyprogram = Compiler(List or string of commands, Default memory size)\n```\n\nThis will create a compiler object and compile the program, accessible with `myprogram.compiled`\n\n```\nmycpu = Cpu(MEMORY_SIZE, myprogram.compiled)\n```\n\nCreate a CPU object with the compiled program and specified memory size (dont change memory size unless you want interesting results)\n\n```\nmycpu.execute()\n```\n\nStart executing commands from memory location 0.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimmsb%2Fcpu_emulator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsimmsb%2Fcpu_emulator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimmsb%2Fcpu_emulator/lists"}