Giter Site home page Giter Site logo

adventofcode2019's Introduction

Advent of Code

This repo is my answers to the 2019 advent of code. Solutions will be published once the leader boards are full

Intcode ASM

I have created an intcode assembler. It uses a custom assembly language to provide a simpler method to writing intcode. Currently it supports the following operations:

Operation Desc
add a b target Adds a to b, and stores the result in target
mul a b target Multiplies a by b, and stores the result in target
ipt target accepts input and stores it in target
out a outputs a
jnz a target Jumps to target if a is not zero (intcode jump if true)
jez a target Jumps to target if a is zero (intcode jump if false)
lt a b target If a is less than b, set target to 1, 0 otherwise
eq a b target If a equals b, set target to 1, 0 otherwise
halt stops the program

The syntax for arguments is inspired by intel ASM.

Prefix Description
None The number as it is literally
r A register
$ A pointer / positional
. The current IP (can be added or subtracted from using .1 and .-1 respectively
! The current Instruction number excluding arguments (replaced with the correct IP for jumps etc). Can be added to or subtracted from using !10 and !-10 respectively

Running the assembler as simple as go run intcodeasm.go

Example

The following code sets position 0 to the number 1337 by multiplying 13 by 100 and then adding 37

% go run intcodeasm.go << EOF                 
heredoc> ipt rCount
heredoc> add -2 rCount rCount
heredoc> add 0 1 rHigh
heredoc> add 0 1 rLow
heredoc> # loop start
heredoc> add 0 rHigh rStore
heredoc> add rLow rHigh rHigh
heredoc> add 0 rStore rLow
heredoc> add -1 rCount rCount
heredoc> jnz rCount !-4
heredoc> out rHigh
heredoc> halt
heredoc> EOF
Intcode for ASM: 003,36,00101,-2,36,36,01101,0,1,37,01101,0,1,38,00101,0,37,39,00001,38,37,37,00101,0,39,38,00101,-1,36,36,1005,36,14,004,37,99,0,0,0,0

adventofcode2019's People

Contributors

a-underscore-d avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.