diff options
author | Nat Lasseter <user@4574.co.uk> | 2019-12-11 21:53:12 +0000 |
---|---|---|
committer | Nat Lasseter <user@4574.co.uk> | 2019-12-11 21:53:12 +0000 |
commit | 693130cae9bdb145af79ee2eb256b661003b6e45 (patch) | |
tree | fc4a450b012545c0f5599c667426d44451fbf71d /day09 | |
parent | 3bea5ec1373b842e6ad9f7cff050615e1f5ebde8 (diff) |
Wrote Intcode (dis-)assembler
Diffstat (limited to 'day09')
-rwxr-xr-x | day09/das | 73 |
1 files changed, 0 insertions, 73 deletions
diff --git a/day09/das b/day09/das deleted file mode 100755 index 9b1eecf..0000000 --- a/day09/das +++ /dev/null @@ -1,73 +0,0 @@ -#!/usr/bin/env ruby - -class Program - def initialize(program) - @mem = program - @pc = 0 - end - - def dis_next - opcode = @mem[@pc] % 100 - - p3, p2, p1 = ("%03d" % (@mem[@pc] / 100)).chars - - print "#{@pc}: " - case opcode - when 1 - puts "add #{Program.sigil(p1)}#{@mem[@pc+1]} #{Program.sigil(p2)}#{@mem[@pc+2]} #{Program.sigil(p3)}#{@mem[@pc+3]}" - @pc += 4 - when 2 - puts "mul #{Program.sigil(p1)}#{@mem[@pc+1]} #{Program.sigil(p2)}#{@mem[@pc+2]} #{Program.sigil(p3)}#{@mem[@pc+3]}" - @pc += 4 - when 3 - puts "in #{Program.sigil(p1)}#{@mem[@pc+1]}" - @pc += 2 - when 4 - puts "out #{Program.sigil(p1)}#{@mem[@pc+1]}" - @pc += 2 - when 5 - puts "jnz #{Program.sigil(p1)}#{@mem[@pc+1]} #{Program.sigil(p2)}#{@mem[@pc+2]}" - @pc += 3 - when 6 - puts "jez #{Program.sigil(p1)}#{@mem[@pc+1]} #{Program.sigil(p2)}#{@mem[@pc+2]}" - @pc += 3 - when 7 - puts "tlt #{Program.sigil(p1)}#{@mem[@pc+1]} #{Program.sigil(p2)}#{@mem[@pc+2]} #{Program.sigil(p3)}#{@mem[@pc+3]}" - @pc += 4 - when 8 - puts "teq #{Program.sigil(p1)}#{@mem[@pc+1]} #{Program.sigil(p2)}#{@mem[@pc+2]} #{Program.sigil(p3)}#{@mem[@pc+3]}" - @pc += 4 - when 9 - puts "arb #{Program.sigil(p1)}#{@mem[@pc+1]}" - @pc += 2 - when 99 - puts "hlt" - @pc += 1 - else - puts "dat #{@mem[@pc]}" - @pc += 1 - end - end - - def dis_all - until @pc >= @mem.length do - dis_next - end - end - - private - - def self.sigil(p) - case p - when "0" - "@" - when "2" - "&" - end - end -end - -input = $stdin.readlines[0].strip.split(",").map(&:to_i) - -p = Program.new(input) -p.dis_all |