{"id":18099970,"url":"https://github.com/rossmacarthur/intcode","last_synced_at":"2025-04-06T04:44:36.959Z","repository":{"id":113965552,"uuid":"394346760","full_name":"rossmacarthur/intcode","owner":"rossmacarthur","description":"🎁 Assembler and runner for the Intcode computer from 🎄 Advent of Code 2019","archived":false,"fork":false,"pushed_at":"2022-03-11T10:33:38.000Z","size":2071,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"trunk","last_synced_at":"2025-02-12T10:55:17.251Z","etag":null,"topics":["advent-of-code","intcode"],"latest_commit_sha":null,"homepage":"https://rossmacarthur.github.io/intcode/","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rossmacarthur.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE-APACHE","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":"2021-08-09T15:36:29.000Z","updated_at":"2022-11-19T09:26:55.000Z","dependencies_parsed_at":"2023-04-04T10:16:08.392Z","dependency_job_id":null,"html_url":"https://github.com/rossmacarthur/intcode","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/rossmacarthur%2Fintcode","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rossmacarthur%2Fintcode/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rossmacarthur%2Fintcode/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rossmacarthur%2Fintcode/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rossmacarthur","download_url":"https://codeload.github.com/rossmacarthur/intcode/tar.gz/refs/heads/trunk","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247436140,"owners_count":20938532,"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":["advent-of-code","intcode"],"created_at":"2024-10-31T21:12:00.673Z","updated_at":"2025-04-06T04:44:36.938Z","avatar_url":"https://github.com/rossmacarthur.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Intcode\n\nAssembler and runner for the Intcode computer from Advent of Code 2019.\n\n## Hello World! program\n\nThe following program outputs \"Hello World!\".\n\n```asm\n    ARB #message  ; move the relative base to the beginning of our message\n\nloop:\n    OUT rb        ; output the current character in the message\n    ARB #1        ; move the relative base to the next character\n    JNZ rb, #loop ; if the next character is non-zero then go back to `loop`\n    HLT\n\nmessage:\n    DB \"Hello World!\\n\"\n```\n\n## Assembly language\n\nThe compiler can assemble the following instruction set specification into an\nIntcode program.\n\n### General\n\nIntcode assembly must be written in a UTF-8 encoded file with Unix line endings.\nComments start with a semicolon `;`.\n\n### Operand types\n\nThere are two types of operands.\n\n- **Label**\n\n  A label refers to an address in a program. For example: `end` in the following program refers the address of the `HLT` instruction.\n  ```asm\n      JZ #0, #end\n  end:\n      HLT\n  ```\n\n- **Number**\n\n  A binary, octal, decimal, or hexadecimal number. This can be used for\n  specifying manual addresses, address offsets, or exact values. For example:\n  the following reads in a value, minuses 3 from it, and outputs the result.\n  ```asm\n  IN  x\n  ADD x, #-0b11, x+1\n  OUT x+0x1\n  HLT\n  ```\n\n### Operand modes\n\nThere are three ways to specify the operands for different instructions.\n\n- **Positional**\n\n  Specifies a value by specifying the *address* it should be read from. For\n  example:\n  - `19` specifies the value at address 19.\n  - `x+3` specifies the value at the label `x` with an offset of 3.\n\n- **Immediate**\n\n  Specifies a value by specifying the exact value. For example:\n  - `#19` specifies the exact value 19.\n  - `#x+3` specifies the exact label address `x` with an offset of 3.\n\n- **Relative**\n\n  Specifies a value by specifying the *address* it should be read from as an\n  offset of the *relative base*. For example:\n  - `rb+3` specifies the value at the relative base address with an offset of 3.\n\n### Opcodes\n\nThe following operations are supported, roughly described in the order they are\nintroduced in Advent of Code.\n\n- **`ADD`**\n\n  Adds the first two operands and stores the result in the third. For example:\n  increment the value at `x`:\n  ```asm\n  ADD x, #1, x\n  ```\n\n- **`MUL`**\n\n  Multiplies the first two operands and stores the result in the third. For\n  example: multiply the value at `x` by 2:\n  ```asm\n  MUL x, #2, x\n  ```\n\n- **`IN`**\n\n  Reads a single number and stores it in the first operand. For example: store\n  input at `x`:\n  ```asm\n  IN x\n  ```\n\n- **`OUT`**\n\n  Outputs a single number and stores it in the first operand. For example:\n  output the value at `x`:\n  ```asm\n  OUT x\n  ```\n\n- **`JNZ`**\n\n  Checks if the first operand is non-zero and then jumps to the value of the\n  second operand. For example: set the instruction pointer to `label` if the\n  value at `x` is non-zero:\n  ```asm\n  JNZ x, #label\n  ```\n\n- **`JZ`**\n\n  Checks if the first operand is zero and then jumps to the value of the second\n  operand. For example: set the instruction pointer to `label` if the value at\n  `x` is zero:\n  ```asm\n  JZ x, #label\n  ```\n\n- **`LT`**\n\n  Checks if the first operand is less than the second. If true, stores 1 in the\n  third operand else stores 0. For example: check if the value at `x` is less\n  than 7 and store the result in `result`:\n  ```asm\n  LT x, #7, result\n  ```\n\n- **`EQ`**\n\n  Checks if the first operand is equal to the second. If true, stores 1 in the\n  third operand else stores 0. For example: check if the value at `x` is equal\n  to 7 and store the result in `result`:\n  ```asm\n  EQ x, #7, result\n  ```\n\n- **`ARB`**\n\n  Adjusts the relative base to the value of the first operand. For example: sets\n  the relative base to the `message` address:\n  ```asm\n  ARB #message\n  ```\n\n- **`HLT`**\n\n  Halts the program. For example:\n  ```asm\n  HLT\n  ```\n\n### Pseudo-opcodes\n\n- **`DB`**\n\n  Places raw data into the program. This must be a sequence of numbers or\n  strings. Strings will be encoded as UTF-8. A label on a `DB` instruction will\n  refer to the start of the data. For example the following specifies the string\n  \"Hello World!\" with a newline.\n  ```asm\n  message:\n      DB \"Hello World!\", 10\n  ```\n\n### Special labels\n\n- **`_`**\n\n  Refers to an undefined address. This should be used to indicate that the\n  address will be set at runtime.\n\n- **`ip`**\n\n  Refers to the address of the next instruction. This can be used to dereference\n  a pointer.\n\nConsider the following example where `ptr` refers to some address and we want to\nread a value into that address. `_` is used because the value of `ptr` will be\nfilled as the parameter for the `IN` instruction by the `ADD` instruction.\n\n```asm\nADD ptr, #0, ip+1\nIN  _\nHLT\n```\n\n## License\n\nLicensed under either of\n\n- Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or\n  http://www.apache.org/licenses/LICENSE-2.0)\n- MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)\n\nat your option.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frossmacarthur%2Fintcode","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frossmacarthur%2Fintcode","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frossmacarthur%2Fintcode/lists"}