Class: Rips::Instructions::Sub

Inherits:
Instruction show all
Defined in:
lib/rips/instructions/sub.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Instruction

#args_number, #code

Constructor Details

#initializeSub

@variables: types of instruction’s variables @length: length in bits for each variable



12
13
14
15
16
# File 'lib/rips/instructions/sub.rb', line 12

def initialize
  super("sub",Formats::DFormat.new(0b0011))
  @variables = [Variables::Register.new, Variables::Register.new, Variables::Register.new]
  @length = {r3:4, r2:4, r1:4, op:4}
end

Instance Attribute Details

#lengthObject (readonly)

Returns the value of attribute length.



8
9
10
# File 'lib/rips/instructions/sub.rb', line 8

def length
  @length
end

#variablesObject (readonly)

Returns the value of attribute variables.



8
9
10
# File 'lib/rips/instructions/sub.rb', line 8

def variables
  @variables
end

Instance Method Details

#set_arguments(args) ⇒ Object

Swap subtractor



19
20
21
22
# File 'lib/rips/instructions/sub.rb', line 19

def set_arguments (args)
  args[1], args[2] = args[2], args[1]
  super
end