Class: Ronin::Code::ASM::Syntax::ATT
- 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
Class Method Summary collapse
-
.emit_immediate_operand(op) ⇒ String
Emits an immediate operand.
-
.emit_instruction(ins) ⇒ String
Emits an instruction.
-
.emit_memory_operand(op) ⇒ String
Emits a memory operand.
-
.emit_operands(ops) ⇒ String
Emits multiple operands.
-
.emit_prologue(program) ⇒ String
Emits the program's prologue.
-
.emit_register(reg) ⇒ String
Emits a register.
-
.emit_section(name) ⇒ String
Emits a section name.
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.
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.
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.
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.
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.
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.
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.
141 142 143 |
# File 'lib/ronin/code/asm/syntax/att.rb', line 141 def self.emit_section(name) ".#{name}" end |