V27 hardened the inline assembler infrastructure. V28 added structured #ASM handling with PB slot binding, stack safety, and privilege gates.
#ASM [options] ... #ENDASMEmbeds 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
Reference PB variables by name inside ASM blocks:
| Syntax | Meaning |
|---|---|
%name | PB storage operand (value at address) |
%udt.field | UDT 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
ASM instructionConvenience syntax for a single assembly instruction. PB slot binding works the same way.
ASM mov rax, %a
#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
#ASM UNSAFEExpert 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
#ASM ALLOW_PRIVILEGEDGates privileged/system mnemonics (CPUID, RDTS C, SYSCALL). Without this flag, privileged instructions are rejected with a diagnostic.
#ASM ALLOW_PRIVILEGED
cpuid
rdtsc
#ENDASM
ASMDATA name ... END ASMDATAEmits 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 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)
~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.