Inline Assembler (V27/V28)

V27 hardened the inline assembler infrastructure. V28 added structured #ASM handling with PB slot binding, stack safety, and privilege gates.

#ASM Block

Syntax: #ASM [options] ... #ENDASM

Embeds x64 assembly directly in PB source. Nonvolatile registers (RBX, RSI, RDI, R12-R15) are automatically saved and restored. Stack alignment is maintained.

#ASM
    mov rax, [rbp - 16]
    add rax, 5
#ENDASM

PB Slot Binding

Reference PB variables by name inside ASM blocks:

SyntaxMeaning
%namePB storage operand (value at address)
%udt.fieldUDT field storage operand
{name}Address of PB storage (usable with LEA)
{udt.field}Address of UDT field (usable with LEA)
LOCAL a AS LONG, p AS Pair
a = 5: p.x = 7
#ASM
    mov rax, %a          ' Load value of a
    add rax, %p.x        ' Add value of p.x
    popcnt rbx, rax
    mov qword ptr %a, rbx  ' Store back to a
    pxor xmm0, xmm0
    movaps xmm1, xmm0
    addps xmm1, xmm0
#ENDASM

Single-Line ASM

Syntax: ASM instruction

Convenience syntax for a single assembly instruction. PB slot binding works the same way.

ASM mov rax, %a

#ASM Options

CLOBBER

Syntax: #ASM CLOBBER reg1 [, reg2, ...]

Informs the compiler that the listed registers are modified by the ASM block. The compiler skips save/restore for these registers (you are responsible).

#ASM CLOBBER RBX
    ' RBX not saved/restored
    mov rbx, rax
#ENDASM

UNSAFE

Syntax: #ASM UNSAFE

Expert mode. Disables RSP balance validation, nonvolatile preservation, and RET rejection. You take full responsibility for stack and register correctness.

#ASM UNSAFE
    ' Expert code here -- no safety checks
#ENDASM

ALLOW_PRIVILEGED

Syntax: #ASM ALLOW_PRIVILEGED

Gates privileged/system mnemonics (CPUID, RDTS C, SYSCALL). Without this flag, privileged instructions are rejected with a diagnostic.

#ASM ALLOW_PRIVILEGED
    cpuid
    rdtsc
#ENDASM

ASMDATA Blocks

Syntax: ASMDATA name ... END ASMDATA

Emits data into the assembly output. Supports db, dw, dd, dq, ascii, asciz directives.

ASMDATA V28Table
    db 1, 2, 3, 4
    dq 1234
END ASMDATA

LINE Graphics (V27)

Syntax: LINE x1, y1, x2, y2 [, color] [, B|BF]

Draws a line on the desktop using GDI calls (MoveToEx, LineTo, Rectangle).

LINE 0, 0, 100, 100       ' Diagonal line
LINE 10, 10, 50, 50, , B  ' Box (future)
V27 uses a desktop DC fallback. Full GRAPHIC WINDOW / DDT-targeted drawing is future work.

Supported x64 Mnemonics

~108 base mnemonics including: mov, lea, add, sub, and, or, xor, cmp, test, imul, div, idiv, push, pop, call, jmp, jcc (30 variants), setcc (30), cmovcc (30), shl/shr/sar/rol/ror/rcl/rcr, inc/dec/not/neg, xchg, movzx/movsx, bsf/bsr, popcnt/tzcnt/lzcnt, bt/bts/btr/btc, nop, ret, int3, leave, cqo, pushfq/popfq, clc/stc/cld/std, cpuid, rdtsc, syscall, ud2.

SSE: cvtsi2sd/cvtsd2si, movsd/addsd/mulsd/subsd/divsd/ucomisd, movaps/movups/movapd/movupd/movdqa/movdqu, addps/subps/mulps/divps/maxps/minps/sqrtps (and PD variants), pxor/pand/por, paddb/w/d/q, psubb/w/d/q.