# Inline Assembly

Vex supports `asm!(...)` expressions for low-level and freestanding code. The current parser accepts the builtin-style operand helpers shown on this page.

## Current Syntax

```vex
unsafe {
    asm!("nop")
}
```

Operands and options are passed as builtin-style helpers inside the `asm!(...)` call.

## Operand Helpers

The parser currently recognizes these forms:

- `$asmIn("constraint", value)`
- `$asmOut("constraint", place)`
- `$asmLateOut("constraint", place)`
- `$asmInOut("constraint", place)`
- `$asmInLateOut("constraint", place)`
- `$asmOpt("pure", "nomem", ...)`
- `$asmClobber("memory", "cc", ...)`

## Basic Example

This no-op example is intended for targets whose assembler accepts `nop`, such
as the tested AArch64 host. It declares no outputs and changes no application
value:

```vex [asm-nop.vx]
fn main(): i32 {
    unsafe { asm!("nop"); }
    $println("continued");
    return 0;
}
```

Run `vex run asm-nop.vx` on a compatible target. Expected stdout is `continued`,
with exit status 0. The example demonstrates the assembly boundary; it is not
a portable delay, memory barrier or synchronization primitive.

## Outputs and Wildcards

An output constraint promises that the assembly writes the selected output.
The instruction must actually define it on every path. A `nop` with an output
constraint does not produce a valid result merely because a destination was
provided. `_` discards a result but does not repair a false output contract.

Use target-specific instruction syntax and the matching register constraints.
A register operand is not automatically a pointer of the width or alignment
required by an instruction.

## Clobbers and Options

Options and clobbers are assertions consumed by code generation. Declare every
register, flag or memory effect the assembly actually has. Do not combine a
claim of no memory effects with a memory effect, or mark a side-effecting
instruction as pure to encourage optimization. Incorrect declarations can
miscompile surrounding code even when the assembler accepts the instruction.

Accepted constraints and option combinations depend on the backend and target.
For a real hardware operation, retain the emitted assembly and test the
surrounding optimized code. Prefer an existing intrinsic or target abstraction
when it already expresses the required effect.

## Legacy Syntax Note

Older `in(...)`, `out(...)`, and similar Rust-style operand forms are no longer the documented surface here. Use the `$asmIn` and `$asmOut` family instead.

## Guidance

1. Keep `asm!` inside `unsafe` blocks.
2. Prefer higher-level intrinsics or stdlib APIs when they exist.
3. Use the narrowest possible constraints and the fewest clobbers needed.
4. Treat inline assembly as target-specific code, not portable application logic.

## Related

- [Freestanding](../freestanding.md)
- [Unsafe](unsafe.md)
- [Builtins](builtins.md)
