Class: Ronin::Code::ASM::Syntax::ATT

Inherits:
Common
  • Object
show all
Defined in:
lib/ronin/code/asm/syntax/att.rb

Overview

Handles emitting Assembly source code in ATT syntax.

Constant Summary collapse

WIDTHS =

Data sizes and their instruction mnemonics

{
  8 => 'q',
  4 => 'l',
  2 => 'w',
  1 => 'b',
  nil => ''
}

Constants inherited from Common

Common::BITS

Class Method Summary collapse

Methods inherited from Common

emit_float, emit_integer, emit_keyword, emit_label, emit_operand, emit_program

Class Method Details

.emit_immediate_operand(op) ⇒ String

Emits an immediate operand.

Parameters:

Returns:

  • (String)

    The formatted immediate operand.



63
64
65
# File 'lib/ronin/code/asm/syntax/att.rb', line 63

def self.emit_immediate_operand(op)
  "$#{emit_integer(op.value)}"
end

.emit_instruction(ins) ⇒ String

Emits an instruction.

Parameters:

Returns:

  • (String)

    The formatted instruction.



116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/ronin/code/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) ⇒ String

Emits a memory operand.

Parameters:

Returns:

  • (String)

    The formatted memory operand.



76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/ronin/code/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) ⇒ String

Emits multiple operands.

Parameters:

Returns:

  • (String)

    The formatted operands.



99
100
101
102
103
104
105
# File 'lib/ronin/code/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) ⇒ String

Emits the program's prologue.

Parameters:

  • program (Program)

    The program.

Returns:

  • (String)

    The formatted prologue.

Since:

  • 0.2.0



156
157
158
# File 'lib/ronin/code/asm/syntax/att.rb', line 156

def self.emit_prologue(program)
  ".code#{BITS[program.arch]}"
end

.emit_register(reg) ⇒ String

Emits a register.

Parameters:

Returns:

  • (String)

    The register name.



50
51
52
# File 'lib/ronin/code/asm/syntax/att.rb', line 50

def self.emit_register(reg)
  "%#{reg.name}"
end

.emit_section(name) ⇒ String

Emits a section name.

Parameters:

  • name (Symbol)

    The section name.

Returns:

  • (String)

    The formatted section name.

Since:

  • 0.2.0



141
142
143
# File 'lib/ronin/code/asm/syntax/att.rb', line 141

def self.emit_section(name)
  ".#{name}"
end