PBXB64 V21

X-Code

X-Code is a separate embedded assembler frontend with a typed dialect and its own parser, command catalogue, virtual registers and register allocation. Within BASIC source it opens with #XCODE and closes only with #ENDX. Its expansion then passes through the integrated inline assembler.

A standalone .asm file uses the ASM frontend. #ASM … #ENDASM, #ACODE … #AEND and individual ! lines use ordinary assembly instructions. X-Code adds X.VREG, X.ADD, X.CLAMP, structured control flow and memory commands. It is an additional embedded dialect layer; the nine registered language inputs reported by --print-capabilities=json plus the separate ASM input are therefore not counted as eleven standalone file frontends.

Options and workflow

OPT=0..3, SPILL=AUTO|ERROR, FEATURES=BASELINE|AUTO|…, REGALLOC=AUTO|MANUAL, APX=AUTO|EMULATE|NATIVE|CHECK.

Virtual registers have types such as U32, U64, I32 or F64. Operands must match each command: X.CLAMP bounds are virtual registers of the same type, rather than immediate numbers. --emit-xcode-asm and --xcode-allocation-report expose the expanded assembly and register allocation.

1. Dedicated X-Code commands

commands.pb
#COMPILE EXE #DIM ALL GLOBAL result AS LONG FUNCTION PBMAIN() AS LONG #XCODE OPT=2, SPILL=AUTO, FEATURES=BASELINE X.VREG value:U32 X.VREG delta:U32 X.MOVE V(value), 5 X.MOVE V(delta), 7 X.ADD V(value), V(delta) X.VREG lower:U32 X.VREG upper:U32 X.MOVE V(lower), 0 X.MOVE V(upper), 10 X.CLAMP V(value), V(lower), V(upper) X.STORE DWORD PTR [result], V(value) #ENDX IF result <> 10 THEN PBMAIN = 1 : EXIT FUNCTION PBMAIN = 0 END FUNCTION

V21: compiled and executed natively on 2026-09-30. The code asserts the clamped result 10; a mismatch returns error 1.

Open checked source

2. Use BASIC variables directly

binding.pb
#COMPILE EXE #DIM ALL GLOBAL source_value AS LONG GLOBAL result AS LONG FUNCTION PBMAIN() AS LONG source_value = 21 #XCODE OPT=2, SPILL=AUTO, FEATURES=BASELINE X.VREG value:U32 X.LOAD V(value), DWORD PTR [source_value] X.ADD V(value), V(value) X.STORE DWORD PTR [result], V(value) #ENDX IF result <> 42 THEN PBMAIN = 1 : EXIT FUNCTION PBMAIN = 0 END FUNCTION

X.LOAD reads the BASIC variable and X.STORE writes the result. V21: native assertion 21 × 2 = 42 passed. DWORD PTR explicitly selects a 32-bit access here.

Open checked source

3. Bridge from another frontend

bridge.pb
#COMPILE EXE #DIM ALL FUNCTION PBMAIN() AS LONG BRIDGE IMPORT counter AS LONG ALIAS "asm_imported_counter" IF counter <> 41 THEN PBMAIN = 1 : EXIT FUNCTION #XCODE OPT=2, SPILL=AUTO, FEATURES=BASELINE X.VREG value:U32 X.LOAD V(value), DWORD PTR [counter] X.INC V(value) X.STORE DWORD PTR [counter], V(value) #ENDX IF counter <> 42 THEN PBMAIN = 2 : EXIT FUNCTION PBMAIN = 0 END FUNCTION

BRIDGE IMPORT binds the exported ASM symbol. V21: both sources compiled together; the native test asserts the initial value 41 and the update to 42. This is shared variable storage rather than a copied value.

Open checked source

provider.asm

section .data global asm_imported_counter asm_imported_counter dq 41

Open ASM source

PBXB64 bridge.pb provider.asm -o bridge.exe bridge.exe

The bridge can bind registered variables from other frontends to BASIC. This specific example checks ASM → BASIC → X-Code; it does not automatically establish every other language pairing.

4. Emulate APX with a separate destination

apx-emulate.pb
#COMPILE EXE #DIM ALL GLOBAL result AS LONG FUNCTION PBMAIN() AS LONG #XCODE OPT=2, SPILL=AUTO, FEATURES=APX, APX=EMULATE mov r16, 1 mov r17, 2 add r18, r16, r17 mov DWORD PTR [result], r18d #ENDX IF result <> 3 THEN PBMAIN = 1 : EXIT FUNCTION PBMAIN = 0 END FUNCTION

V21: translated and executed natively on the current x64 system; result 1 + 2 = 3 asserted. Emulation maps APX registers onto existing x64 registers and does not require native APX hardware for this example.

Open checked source

Fixed in V23

With add r16, r17, r16 and initial values 1 and 2, the emulation in the released V8 compiler (PBXB64 V23) returns the correct result 3, also when the destination is one of the source registers. Checked on 2026-10-05 on a processor without APX.

5. Inspect native APX encoding

apx-native.pb
#COMPILE EXE #DIM ALL FUNCTION PBMAIN() AS LONG PBMAIN = 0 #XCODE OPT=2, SPILL=AUTO, FEATURES=APX, APX=NATIVE mov r16, 1 mov r17, 2 add r16, r17, r16 #ENDX END FUNCTION

V21: compilation and encoding checks only. Expected REX2/EVEX bytes are present. This program was not executed natively; the CPU must support the APX instructions used. Translation does not prove hardware execution.

Open checked source
PBXB64 apx-native.pb -o apx-native.exe --emit-xcode-asm native.asm DB 0xD5, 0x18, 0xC7, 0xC0, 0x01, 0x00, 0x00, 0x00 DB 0xD5, 0x18, 0xC7, 0xC1, 0x02, 0x00, 0x00, 0x00 DB 0x62, 0xEC, 0xFC, 0x10, 0x01, 0xC1

These three lines are checked excerpts of native.asm. APX-EMULATE and APX-NATIVE have different verification scopes.

Verification and references

The stated checks use the byte-identical PBXB64 0.50.0-V21 executable from the PBX V7 package. Inputs, verification scope, compiler hash and timestamp are recorded per example. Individual examples do not replace full compiler qualification. The shipped frontend documentation and X-Code chapters of the CHM help cover block syntax, commands, registers, options and APX.

View verification receipts#OVERRIDE / Preprocessor
Back to feature list