Class: Ragweed::Rasm::Cmp

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

Overview

CMP is SUB + condition code

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) ⇒ Cmp

3c imm8 3d imm 80/7 r/m8, imm8 81/7 r/m, imm 83/7 r/m, imm8 38 r/m8, r8 39 r/m, r 3a r8, r/m8 3b r, r/m



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

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

Instance Method Details

#to_sObject



719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
# File 'lib/ragweed/rasm/isa.rb', line 719

def to_s
  if not @dst
    raise(BadArg, "need immed for implicit ax") if not src_imm?
    if @src.val < 0x100
      add(0x3c)
      add(@src.val)
    else
      add(0x3d)
      add(@src.val)
    end
  else
    raise(BadArg, "need reg dst") if not dst_reg?
    if src_imm?
      raise NotImp if @dst.byte
      if @src.val < 0x100
        add(0x83)
        add(modrm(@dst, Edi.clone))
        add(@src.val)
      else
        add(0x81)
        add(modrm(@dst, Edi.clone))
        add(@src.val)
      end
    else
      if @dst.indir
        add(0x39)
        add(modrm(@src, @dst))
        add(@dst.disp)
      else
        add(0x3b)
        add(modrm(@src, @dst))
        add(@dst.disp)
      end
    end
  end
  super
end