Class: Hackasm::Commands::Asm2Binary

Inherits:
Hackasm::Command show all
Defined in:
lib/hackasm/commands/asm2binary.rb

Constant Summary collapse

FILE_NAME =
"a.hack".freeze

Instance Method Summary collapse

Methods inherited from Hackasm::Command

#command, #cursor, #editor, #exec_exist?, #generator, #pager, #platform, #prompt, #screen, #which

Constructor Details

#initialize(file, options) ⇒ Asm2Binary

Returns a new instance of Asm2Binary.



11
12
13
14
# File 'lib/hackasm/commands/asm2binary.rb', line 11

def initialize(file, options)
  @file = file
  @options = options
end

Instance Method Details

#execute(input: $stdin, output: $stdout) ⇒ Object



16
17
18
19
20
21
22
23
# File 'lib/hackasm/commands/asm2binary.rb', line 16

def execute(input: $stdin, output: $stdout)
  assembler_code = File.read(@file)

  binary = Assembler::Translator.new(assembler_code).translate

  output.puts binary
  File.write(FILE_NAME, binary)
end