class Ronin::ASM::Syntax::ATT

Handles emitting Assembly source code in ATT syntax.

Constants

WIDTHS

Data sizes and their instruction mnemonics

Public Class Methods

emit_immediate_operand(op) click to toggle source

Emits an immediate operand.

@param [ImmediateOperand] op

The operand.

@return [String]

The formatted immediate operand.
# File lib/ronin/asm/syntax/att.rb, line 63
def self.emit_immediate_operand(op)
  "$#{emit_integer(op.value)}"
end
emit_instruction(ins) click to toggle source

Emits an instruction.

@param [Instruction] ins

The instruction.

@return [String]

The formatted instruction.
# File lib/ronin/asm/syntax/att.rb, line 116
def self.emit_instruction(ins)
  line = emit_keyword(ins.name)

  unless ins.operands.empty?
    unless (ins.operands.length == 1 && ins.width == 1)
      line << WIDTHS[ins.width]
    end

    line << "\t" << emit_operands(ins.operands)
  end

  return line
end
emit_memory_operand(op) click to toggle source

Emits a memory operand.

@param [MemoryOperand] op

The operand.

@return [String]

The formatted memory operand.
# File lib/ronin/asm/syntax/att.rb, line 76
def self.emit_memory_operand(op)
  asm = emit_register(op.base)

  if op.index
    asm << ',' << emit_register(op.index)
    asm << ',' << op.scale.to_s if op.scale > 1
  end

  asm = "(#{asm})"
  asm = emit_integer(op.offset) + asm if op.offset != 0

  return asm
end
emit_operands(ops) click to toggle source

Emits multiple operands.

@param [Array<ImmediateOperand, MemoryOperand, Register, Symbol>] ops

The Array of operands.

@return [String]

The formatted operands.
Calls superclass method
# File lib/ronin/asm/syntax/att.rb, line 99
def self.emit_operands(ops)
  if ops.length > 1
    [*ops[1..-1], ops[0]].map { |op| emit_operand(op) }.join(",\t")
  else
    super(ops)
  end
end
emit_prologue(program) click to toggle source

Emits the program’s prologue.

@param [Program] program

The program.

@return [String]

The formatted prologue.

@since 0.2.0

# File lib/ronin/asm/syntax/att.rb, line 156
def self.emit_prologue(program)
  ".code#{BITS[program.arch]}"
end
emit_register(reg) click to toggle source

Emits a register.

@param [Register] reg

The register.

@return [String]

The register name.
# File lib/ronin/asm/syntax/att.rb, line 50
def self.emit_register(reg)
  "%#{reg.name}"
end
emit_section(name) click to toggle source

Emits a section name.

@param [Symbol] name

The section name.

@return [String]

The formatted section name.

@since 0.2.0

# File lib/ronin/asm/syntax/att.rb, line 141
def self.emit_section(name)
  ".#{name}"
end