Class: SCASM::Instruction
Instance Attribute Summary collapse
-
#a ⇒ Object
readonly
Returns the value of attribute a.
-
#b ⇒ Object
Returns the value of attribute b.
-
#opsym ⇒ Object
readonly
Returns the value of attribute opsym.
Attributes inherited from Statement
Instance Method Summary collapse
- #assemble(io) ⇒ Object
-
#initialize(opsym, a, b) ⇒ Instruction
constructor
A new instance of Instruction.
- #to_s ⇒ Object
Methods inherited from Statement
Constructor Details
#initialize(opsym, a, b) ⇒ Instruction
Returns a new instance of Instruction.
28 29 30 31 32 |
# File 'lib/scasm/statement.rb', line 28 def initialize opsym, a, b @opsym = opsym @a = a @b = b end |
Instance Attribute Details
#a ⇒ Object (readonly)
Returns the value of attribute a.
25 26 27 |
# File 'lib/scasm/statement.rb', line 25 def a @a end |
#b ⇒ Object
Returns the value of attribute b.
25 26 27 |
# File 'lib/scasm/statement.rb', line 25 def b @b end |
#opsym ⇒ Object (readonly)
Returns the value of attribute opsym.
25 26 27 |
# File 'lib/scasm/statement.rb', line 25 def opsym @opsym end |
Instance Method Details
#assemble(io) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/scasm/statement.rb', line 34 def assemble io if opcode = BASIC_OPCODES[@opsym] code_a, imm_a = @a.assemble code_b, imm_b = @b.assemble code = opcode | (code_a<<4) | (code_b<<10) io.write [code, imm_a, imm_b].compact.pack('v*') elsif opcode = EXTENDED_OPCODES[@opsym] code_a, imm_a = @a.assemble fail unless @b == nil code = (opcode<<4) | (code_a<<10) io.write [code, imm_a].compact.pack('v*') else fail "unknown opsym #{@opsym.inspect}" end end |
#to_s ⇒ Object
50 51 52 |
# File 'lib/scasm/statement.rb', line 50 def to_s "%s %s, %s" % [@opsym, @a, @b] end |