Class: Ragweed::Rasm::Arith

Inherits:
Instruction show all
Defined in:
lib/ragweed/rasm/isa.rb

Overview

Wrapper class for arithmatic instructions. Never called directly; see below.

Direct Known Subclasses

Add, And, Or, Sub, Xor

Instance Attribute Summary

Attributes inherited from Instruction

#dst, #src

Instance Method Summary collapse

Methods inherited from Instruction

#add, #coerce, #dst_imm?, #dst_lab?, #dst_reg?, i, #locate, #modrm, #patch, #sib, #src_imm?, #src_lab?, #src_reg?

Constructor Details

#initialize(dst = nil, src = nil) ⇒ Arith

05 imm32 to eax 04 imm8 to al 80/0 r/m8, imm8 81/0 r/m, imm no sign extend yet 01 r/m, r 03 r, r/m



569
# File 'lib/ragweed/rasm/isa.rb', line 569

def initialize( dst=nil, src=nil); super dst, src; end

Instance Method Details

#to_sObject



571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
# File 'lib/ragweed/rasm/isa.rb', line 571

def to_s
  if not @dst
    # fucked up
    if src_imm?
      if @src.val < 0x100
        add(@imp8)
        add(@src.val)
      else
        add(@imp)
        add(@src.val)
      end
    else
      raise BadArg, "need immed for implicit eax"
    end
  else
    if src_imm?
      if @src.val < 0x100
        add(@imm8)
        add(modrm(@dst, @x))
        add(@src.val)
      else
        add(@imm)
        add(modrm(@dst, @x))
        add(@src.val)
      end
    else
      raise(BadArg, "need two r/m") if not src_reg? or not dst_reg?
      raise(BadArg, "can't both be indir") if @src.indir and @dst.indir
      if @src.indir
        add(@rm)
        add(modrm(@dst, @src))
      else
        add(@mr)
        add(modrm(@dst, @src))
      end
    end
  end
  super
end