Overview
This final stage converts abstract assembly instructions into concrete x86-64 assembly text, then delegates to the system toolchain for assembly and linking. Input:asm::Program<'db> (assembly IR)Output: Executable binary (via external toolchain)
Modules:
crates/mcc/src/render.rs, crates/mcc/src/assembling.rs
Rendering Pipeline
Entry Point
target parameter (from target-lexicon) controls platform-specific syntax.
Assembly Renderer
Program Structure
.note.GNU-stack section for executable stack marking.
Function Rendering
Function Prologue
- macOS/Darwin: Prefix with
_(e.g.,_main) - Linux: No prefix (e.g.,
main)
Instruction Rendering
Stack Allocation
Moves
movl (32-bit move) in AT&T syntax: movl source, destination.
Unary Operations
Negation:cmpl $0, operand– Compare with zerosete %al– Set AL to 1 if zero flag is setmovb %al, operand– Copy byte to operand
Binary Operations
Division
cdq– Sign-extend%eaxinto%edx:%eaxidivl– Signed divide%edx:%eaxby operand
Comparisons
cmpl right, left– Set flags based onleft - rightsetcc %al– Set AL to 0 or 1 based on conditionmovzbl %al, %eax– Zero-extend to 32 bitsmovl %eax, dst– Store result
Control Flow
Labels:testlperforms bitwise AND and sets flags (without storing result)jz/jnzjump based on zero flag
Return
Operand Formatting
- Immediates:
$42 - Registers:
%eax - Memory:
-8(%rbp)(offset from base pointer)
Assembly and Linking
Defined inassembling.rs:
- Input: Assembly
.sfile - Output: Executable binary
-arch flag to target x86-64 on ARM Macs.
Example
Assembly IR Input:_main prefix on macOS.
Related Stages
- Previous: Code Generation – Produces assembly IR
- External Tools:
gcc/clangfor assembling and linking - Output: Native executable for target platform