Class Voodoo::AMD64NasmGenerator
In: voodoo/generators/amd64_nasm_generator.rb
Parent: NasmGenerator

AMD64 NASM Code Generator

Code generator that emits NASM assembly code for AMD64 processors.

Calling Convention

The calling convention implemented by this code generator is compatible with the System V ABI for AMD64, provided that all arguments are integers or pointers.

Arguments are passed in registers. The registers are used in the following order:

  1. rdi
  2. rsi
  3. rdx
  4. rcx
  5. +r8+
  6. +r9+

Additional arguments are pushed on the stack, starting with the last argument and working backwards. These arguments are removed from the stack by the caller, after the called function returns.

The return value is passed in rax.

For varargs functions, rax must be set to an upper bound on the number of vector arguments. Since the code generator does not know whether the called function is a varargs function, this is always done. Since the code generator never passes any vector arguments, this means rax is set to +0+ before each call.

Call Frames

  arg_n
  :
  arg_7
  arg_6
  saved_rip
  saved_rbp <-- rbp
  arg_0
  arg_1
  :
  arg_5
  local_0
  local_1
  :
  local_n   <-- rsp

Methods

Public Class methods

Public Instance methods

Call a function.

Introduce a new local variable

Load the value of the nth argument

Load the value of the nth local variable

Calculate the number of register arguments, given the total number of arguments. If n is nil, returns the maximum number of register arguments.

Calculate the number of stack arguments, given the total number of arguments.

Load a value and push it on the stack.

Tests if the nth argument is a register argument.

Call a function, re-using the current call frame if possible.

Define a machine word with the given value.

[Validate]