{"id":15653660,"url":"https://github.com/drom/quark","last_synced_at":"2026-02-07T05:01:08.846Z","repository":{"id":145177354,"uuid":"45230555","full_name":"drom/quark","owner":"drom","description":"Stack CPU :construction: Work In Progress :construction:","archived":false,"fork":false,"pushed_at":"2024-01-01T00:51:45.000Z","size":61,"stargazers_count":30,"open_issues_count":5,"forks_count":2,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-07-23T13:31:09.245Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Verilog","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/drom.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":".github/CONTRIBUTING.md","funding":".github/FUNDING.yml","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},"funding":{"custom":["https://paypal.me/wavedrom","wavedrom.com"],"patreon":"drom","ko_fi":"wavedrom"}},"created_at":"2015-10-30T05:16:15.000Z","updated_at":"2024-08-29T13:44:39.000Z","dependencies_parsed_at":"2024-01-01T01:43:28.433Z","dependency_job_id":null,"html_url":"https://github.com/drom/quark","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/drom/quark","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drom%2Fquark","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drom%2Fquark/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drom%2Fquark/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drom%2Fquark/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/drom","download_url":"https://codeload.github.com/drom/quark/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drom%2Fquark/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29186742,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-07T03:35:06.566Z","status":"ssl_error","status_checked_at":"2026-02-07T03:34:57.604Z","response_time":63,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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-10-03T12:46:24.093Z","updated_at":"2026-02-07T05:01:08.828Z","avatar_url":"https://github.com/drom.png","language":"Verilog","funding_links":["https://paypal.me/wavedrom","wavedrom.com","https://patreon.com/drom","https://ko-fi.com/wavedrom"],"categories":[],"sub_categories":[],"readme":"# Stack HAT\n\n## Introduction\n\nQUARK is a simple dual-stack CPU instruction set architecture (ISA) that can be extended.\n\nQUARK uses Head-and-tail instruction format, described in [Hedi01](http://www.cs.berkeley.edu/~krste/papers/hat-cases2001.pdf)\n\n![ISA](https://rawgit.com/drom/quark/master/isa.svg)\n\n## Instructions\n\nQUARK has integer data-path width 16, 32, 64 or 128. (isa16, isa32, isa64, isa128)\n\nIt has two stack units data stack (DS) and return stack (RS) of base width and configurable depth.\n\nEach instruction has 4-bit `Head` part that defines following side effects:\n - Stack effect (DS and RS) change of the stack depth and marked position\n - Load / Store effect\n - Control flow change (branch)\n - Size of `Tail`\n\nEach instruction has 4, 8, 16 or 32 bit `Tail`.\n\nThe following table describes  \n\n| N | name   | description         | tail | tail           | DS                    | RS\n|---| ------ | ------------------- | ---- | -------------- | --------------------- | --------\n| 0 | LIT4   | push literal to DS  | 4    | imm4           | ( -- n )              |\n| 1 | LIT8   | --//--              | 8    | imm8           | ( -- n )              |\n| 2 | LIT16  | --//--              | 16   | imm16          | ( -- n )              |\n| 3 | LIT32  | --//--              | 32   | imm32          | ( -- n )              |\n| 4 | BRANCH | branch              | 4    | kind           | ( addr -- )           |\n| 5 |        |                     |      |                |                       |\n| 6 |        |                     |      |                |                       |\n| 7 | CALL   | subroutine call     |      |                | ( addr -- )           | ( -- pc )\n| 8 | LOAD   | load from memory    | 4    | load type      | ( addr -- data )      |\n| 9 | PICK   | copy Nth DS element | 4    | element number | ( -- n )              |\n| A | DUP    | copy DS top         |      |                | ( n -- n n )          |\n| B | R\u003e     | move RS top -\u003e DS   |      |                | ( -- n )              | ( n -- )\n| C | STORE  | store to the memory | 4    | store type     | ( data addr -- addr ) |\n| D | ALU    | ALU operations      | 4    | operation      | ( a b -- c )          |\n| E | DROP   | DS pop              |      |                | ( n -- )              |\n| F | \u003eR     | move DS top -\u003e RS   |      |                | ( n -- )              | ( -- n )\n\n## imm4, imm8, imm16, imm32\n\nSign extended immediate value that will be pushed into DS.\n\n## BRANCH Kinds\n\n| N | name | description\n|---|------|------------\n| 0 | JMP  | unconditional\n| 1 | BDZ  | second element of DS is equal 0\n| 2 | DRZ  | top element on RS is equal 0\n\n## Load type\n\n| N | name     | description\n|---|----------|------------\n| 0 | load8_s  | load 1 byte with sign-extention\n| 1 | load8_u  | load 1 byte zero extended\n| 2 | load16_s | load 2 bytes with sign-extention\n| 3 | load16_u | load 2 bytes zero extended\n| 4 | load32_s | load 4 bytes with sign-extention\n| 5 | load32_u | load 4 bytes zero extended\n| 6 | load64_s | load 8 bytes with sign-extention\n| 7 | load64_u | load 8 bytes zero extended\n| 8 | load128  | load 16 bytes\n\n```\nisa16:  0 1 2\nisa32:  0 1 2 3 4\nisa64:  0 1 2 3 4 5 6\nisa128: 0 1 2 3 4 5 6 7 8\n```\n\n## Stores\n\n| N | name     | description\n|---|----------|------------\n| 0 | store8   | store 1 byte\n| 1 | store16  | store 2 bytes\n| 2 | store32  | store 4 bytes\n| 3 | store64  | store 8 bytes\n| 4 | store128 | store 16 bytes\n\n```\nisa16:  0 1\nisa32:  0 1 2\nisa64:  0 1 2 3\nisa128: 0 1 2 3 4\n```\n\n\n## ALU\n\n| N | name  | description\n|---|-------|------------\n| 0 | add   | sign-agnostic addition\n| 1 | sub   | sign-agnostic subtraction\n| 2 | ssub  | swap and sign-agnostic subtraction\n| 3 | and   | sign-agnostic bitwise and\n| 4 | or    | sign-agnostic bitwise inclusive or\n| 5 | xor   | sign-agnostic bitwise exclusive or\n| 6 | shl   | sign-agnostic shift left\n| 7 | shr_u | zero-replicating (logical) shift right\n| 8 | shr_s | sign-replicating (arithmetic) shift right\n| 9 | rotl  | sign-agnostic rotate left\n| 10| rotr  | sign-agnostic rotate right\n|   |       |\n|   | mul   | sign-agnostic multiplication\n|   | div_s | signed division (result is truncated toward zero)\n|   | div_u | unsigned division (result is floored)\n|   | rem_s | signed remainder (result has the sign of the dividend)\n|   | rem_u | unsigned remainder\n|   | eq    | sign-agnostic compare equal\n|   | ne    | sign-agnostic compare unequal\n|   | lt_s  | signed less than\n|   | le_s  | signed less than or equal\n|   | lt_u  | unsigned less than\n|   | le_u  | unsigned less than or equal\n|   | gt_s  | signed greater than\n|   | ge_s  | signed greater than or equal\n|   | gt_u  | unsigned greater than\n|   | ge_u  | unsigned greater than or equal\n|   | clz   | sign-agnostic count leading zero bits (All zero bits are considered leading if the value is zero)\n|   | ctz   | sign-agnostic count trailing zero bits (All zero bits are considered trailing if the value is zero)\n|   | popcnt| sign-agnostic count number of one bits\n|   | eqz   | compare equal to zero (return 1 if operand is zero, 0 otherwise)\n\n## isa32 / 64-bit instruction word\n\n- 0..15 head slots\n- [63:4] head range\n- 0..7 tail slots\n- [63:16] tail range\n- [63,59,55,51,47,..,23] (11) MSB positions\n\n### LE\n\n![instr64](instr64_LE.svg)\n\n### BE\n\n![instr64](instr64_BE.svg)\n\n### LE Examples\n\n![instr64](instr64_cases.svg)\n\n### RISC-V extension\n\nhttps://beta.observablehq.com/@drom/quark\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdrom%2Fquark","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdrom%2Fquark","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdrom%2Fquark/lists"}