Class: Gruesome::Z::Instruction
- Inherits:
-
Object
- Object
- Gruesome::Z::Instruction
- Defined in:
- lib/gruesome/z/instruction.rb
Overview
A Z-Machine instruction
Instance Attribute Summary collapse
-
#branch_on ⇒ Object
readonly
also…
-
#branch_to ⇒ Object
readonly
the address to set the pc when branch is taken.
-
#destination ⇒ Object
readonly
the destination variable to place the result.
-
#length ⇒ Object
readonly
instruction size in number of bytes.
-
#opcode ⇒ Object
readonly
the opcode.
-
#operands ⇒ Object
readonly
the operands given to the instruction.
-
#types ⇒ Object
readonly
the types of the operands.
Instance Method Summary collapse
-
#initialize(opcode, types, operands, destination, branch_destination, branch_condition, length) ⇒ Instruction
constructor
A new instance of Instruction.
- #to_s(version) ⇒ Object
Constructor Details
#initialize(opcode, types, operands, destination, branch_destination, branch_condition, length) ⇒ Instruction
Returns a new instance of Instruction.
16 17 18 19 20 21 22 23 24 |
# File 'lib/gruesome/z/instruction.rb', line 16 def initialize(opcode, types, operands, destination, branch_destination, branch_condition, length) @opcode = opcode @types = types @operands = operands @destination = destination @branch_to = branch_destination @branch_on = branch_condition @length = length end |
Instance Attribute Details
#branch_on ⇒ Object (readonly)
also… if 0, return true from routine
if 1, return false from routine
13 14 15 |
# File 'lib/gruesome/z/instruction.rb', line 13 def branch_on @branch_on end |
#branch_to ⇒ Object (readonly)
the address to set the pc when branch is taken
10 11 12 |
# File 'lib/gruesome/z/instruction.rb', line 10 def branch_to @branch_to end |
#destination ⇒ Object (readonly)
the destination variable to place the result
9 10 11 |
# File 'lib/gruesome/z/instruction.rb', line 9 def destination @destination end |
#length ⇒ Object (readonly)
instruction size in number of bytes
14 15 16 |
# File 'lib/gruesome/z/instruction.rb', line 14 def length @length end |
#opcode ⇒ Object (readonly)
the opcode
6 7 8 |
# File 'lib/gruesome/z/instruction.rb', line 6 def opcode @opcode end |
#operands ⇒ Object (readonly)
the operands given to the instruction
8 9 10 |
# File 'lib/gruesome/z/instruction.rb', line 8 def operands @operands end |
#types ⇒ Object (readonly)
the types of the operands
7 8 9 |
# File 'lib/gruesome/z/instruction.rb', line 7 def types @types end |
Instance Method Details
#to_s(version) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/gruesome/z/instruction.rb', line 26 def to_s(version) line = Opcode.name(@opcode, version) idx = -1 line = line + @operands.inject("") do |result, element| idx += 1 if @types[idx] == OperandType::VARIABLE result + " %" + sprintf("%02x", element) else result + " " + element.to_s end end if @destination != nil line = line + " -> %" + sprintf("%02x", @destination) end if @branch_to != nil line = line + " goto $" + sprintf("%04x", @branch_to) + " on " + @branch_on.to_s end line end |