2014-04-17 14:35:55 +02:00
|
|
|
require "asm/assembly_error"
|
2014-04-23 11:51:09 +02:00
|
|
|
require "asm/instruction_tools"
|
2014-04-23 12:52:34 +02:00
|
|
|
require "asm/label"
|
2014-04-14 20:52:16 +02:00
|
|
|
|
2014-04-14 17:09:56 +02:00
|
|
|
module Asm
|
2014-04-14 20:52:16 +02:00
|
|
|
|
2014-04-23 22:40:35 +02:00
|
|
|
class Instruction
|
|
|
|
include InstructionTools
|
2014-04-14 17:09:56 +02:00
|
|
|
|
2014-04-23 22:40:35 +02:00
|
|
|
COND_POSTFIXES = Regexp.union( COND_CODES.keys.collect{|k|k.to_s} ).source
|
2014-04-14 17:09:56 +02:00
|
|
|
|
2014-04-23 22:40:35 +02:00
|
|
|
def initialize(opcode , args)
|
|
|
|
opcode = opcode.to_s.downcase
|
|
|
|
@cond = :al
|
|
|
|
if (opcode =~ /(#{COND_POSTFIXES})$/)
|
|
|
|
@cond = $1.to_sym
|
|
|
|
opcode = opcode[0..-3]
|
|
|
|
end unless opcode == 'teq'
|
|
|
|
if (opcode =~ /s$/)
|
|
|
|
@update_status_flag= 1
|
|
|
|
opcode = opcode[0..-2]
|
|
|
|
else
|
|
|
|
@update_status_flag= 0
|
2014-04-14 17:09:56 +02:00
|
|
|
end
|
2014-04-23 22:40:35 +02:00
|
|
|
@opcode = opcode.downcase.to_sym
|
|
|
|
@args = args
|
|
|
|
@operand = 0
|
|
|
|
end
|
|
|
|
attr_reader :opcode, :args , :position , :cond , :operand , :update_status_flag
|
2014-04-14 17:09:56 +02:00
|
|
|
|
2014-04-23 22:40:35 +02:00
|
|
|
def affect_status
|
|
|
|
@s
|
|
|
|
end
|
2014-04-17 11:54:37 +02:00
|
|
|
|
2014-04-23 22:40:35 +02:00
|
|
|
def at position
|
|
|
|
@position = position
|
|
|
|
end
|
|
|
|
|
|
|
|
def length
|
|
|
|
4
|
|
|
|
end
|
|
|
|
|
|
|
|
def assemble(io, as)
|
|
|
|
raise "Abstract class, should not be called/instantiated #{self.inspect}"
|
2014-04-14 17:09:56 +02:00
|
|
|
end
|
2014-04-23 22:40:35 +02:00
|
|
|
end
|
2014-04-14 17:09:56 +02:00
|
|
|
end
|