1 Overview🔗

 (require a86) package: a86

This library provides functions for composing, printing, and running x86-64 assembly programs in Racket:

Examples

; Natural -> Asm
; Produce representation of assembly program to compute n! recursively
> (define (fact-program n)
    (list (Global 'run)
          (Label 'run)
          (Mov 'rax n)
          (Label 'fact)
          (Cmp 'rax 0)
          (Je 'done)
          (Push 'rax)
          (Sub 'rax 1)
          (Call 'fact)
          (Pop 'r9)
          (Mul 'r9)
          (Ret)
          (Label 'done)
          (Mov 'rax 1)
          (Ret)))
; compute 5!
> (asm-interp (fact-program 5))

120

; render 5! program in NASM syntax
> (asm-display (fact-program 5))

        default rel

        section .text

        global $run

$run:

        mov rax, 5

$fact:

        cmp rax, 0

        je $done

        push rax

        sub rax, 1

        call $fact

        pop r9

        mul r9

        ret

$done:

        mov rax, 1

        ret

Programs consist of a list of Instructions and Psuedo-Instructions. Instructions can take as arguments Labels, Immediates, Registers and Memory Expressions.

Executing instructions can read and modify Registers and Memory, including the Stack.

The a86 module provides all of the bindings from a86/ast, a86/registers, a86/printer, and a86/interp, described below.