Class Voodoo::NasmGenerator
In: voodoo/generators/nasm_generator.rb
Parent: CommonCodeGenerator

NASM Code Generator

The NASM code generator is a common base class for generators that output assembly code for use with the Netwide Assembler.

This class is used by both the I386NasmGenerator and the AMD64NasmGenerator, and contains the functionality that is common to both.

To use the functionality from this class, a subclass must define the following methods and constants:

  • emit_function_prologue
  • load_arg
  • load_local
  • @CODE_ALIGNMENT
  • @DATA_ALIGNMENT
  • @FUNCTION_ALIGNMENT
  • @SCRATCH_REG
  • @WORD_NAME
  • @WORDSIZE
  • @AX, @BX, @CX, @DX, @BP, and @SP

Methods

Public Class methods

Public Instance methods

Translates a Voodoo action name to an x86 mnemonic

Test if a value is an at-expression

Begins a new block.

Emit function preamble and declare formals as function arguments

Emit code for a binary operation

Emit code for a binary operation where the first operand is also the target

Test if op is a binary operation

Define a byte with the given value

Start a conditional using the specified branch instruction after the comparison.

Divide x by y and store the quotient in target

Divide target by x and store the quotient in target

Define a dword with the given value

Ends the current block.

End a function body

End a conditional.

End a conditional body

Perform division. The quotient is stored in @AX, the remainder in @DX.

Evaluate an expression. The result is stored in register (@RETURN_REG by default). The following registers may be clobbered: @AX, @BX, @CX, @DX

Multiply x by y. The result is stored in @AX by default, but a different register can be specified by passing a third argument.

Export symbols from the current section

Test if a symbol refers to a global

Continue execution at the given address

Start the false path of a conditional.

Test if x is equal to y

Test if x is greater than or equal to y

Test if x is strictly greater than y

Test if x is less than or equal to y

Test if x is strictly less than y

Test if x different from y

Tests if an operand is an immediate operand

Import labels into the current section

Test if a value is an integer

Define a label in the current section

Create a value reference to an address. Invoking this code may clobber @BX and/or @CX

Load the value at the given address. Invoking this code may clobber @BX.

Load the value associated with the given symbol. Returns a string that can be used to refer to the loaded value.

Load a value. Returns a string that can be used to refer to the loaded value.

Load a value into a register

Load a value into a register.

Tests if an operand is a memory operand

Divide x by y and store the remainder in target

Divide target by x and store the remainder in target

Multiply x by y and store the result in target

Multiply target by x and store the result in target

Define a qword with the given value

Return a from a function.

words may contain an expression to be evaluated. The result of the evaluation is returned from the function.

Evaluate the expr in words and store the result in target

Set the byte at base + offset to value

Set a register to a value. The value must be a valid operand to the mov instruction.

Set the word at base + offset * +@WORDSIZE+ to value

Define a string with the given value

Test if a value is a symbol

Test if op is a symmetric operation (i.e. it will yield the same result if the order of its source operands is changed).

Write generated code to the given IO object.

[Validate]