Class: Rips::Instructions::Instruction
- Inherits:
-
Object
- Object
- Rips::Instructions::Instruction
- Defined in:
- lib/rips/instructions/instruction.rb
Direct Known Subclasses
Add, And, Beqz, Bnez, J, Jal, Ji, Jr, Lesr, Lest, Li, Move, Neg, Nop, Not, Or, Print, Sesm, Sesr, Srl, Sub
Instance Method Summary collapse
-
#args_number ⇒ Object
Return number of arguments.
-
#code ⇒ Object
Coding to Machine Code.
-
#initialize(name, format) ⇒ Instruction
constructor
@name: mnemonic name @format: instruction format @output: array with coded instruction.
-
#set_arguments(args) ⇒ Object
Pass all arguments at once.
Constructor Details
#initialize(name, format) ⇒ Instruction
@name: mnemonic name @format: instruction format @output: array with coded instruction
18 19 20 21 22 |
# File 'lib/rips/instructions/instruction.rb', line 18 def initialize (name, format) @name,@format = name,format @opcode = format.opcode @output = [] end |
Instance Method Details
#args_number ⇒ Object
Return number of arguments
40 41 42 |
# File 'lib/rips/instructions/instruction.rb', line 40 def args_number @format.args_number end |
#code ⇒ Object
Coding to Machine Code
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/rips/instructions/instruction.rb', line 50 def code # Add opcode @output = [@opcode.to_bin(@length[:op])] # Add arguments @format.args.each do |key,value| @output << value.to_bin(@length[key]) end # Add blanks if (@length.key? :blank) add_blank end @output.reverse.join.to_s end |
#set_arguments(args) ⇒ Object
Pass all arguments at once
45 46 47 |
# File 'lib/rips/instructions/instruction.rb', line 45 def set_arguments (args) @format.set_arguments(args) end |