' Multi-Language Demo — PB + ASM integrated
#COMPILE EXE
#DIM ALL

FUNCTION AddASM(BYVAL a AS LONG, BYVAL b AS LONG) AS LONG
    #ASM
        mov eax, ecx
        add eax, edx
        leave
        ret
    #ENDASM
END FUNCTION

FUNCTION GCD(a AS LONG, b AS LONG) AS LONG
    LOCAL tmp AS LONG
    WHILE b > 0
        tmp = b
        b = a MOD b
        a = tmp
    WEND
    FUNCTION = a
END FUNCTION

FUNCTION PBMAIN() AS LONG
    LOCAL a AS LONG, b AS LONG, c AS LONG
    LOCAL i AS LONG, j AS LONG, tmp AS LONG

    PRINT "Multi-Language Demo (PB + ASM)"
    PRINT "=============================="
    PRINT ""

    PRINT "ASM section:"
    a = 40: b = 50
    c = AddASM(a, b)
    PRINT "  AddASM(40, 50) = "; c

    a = 100: b = 200
    c = AddASM(a, b)
    PRINT "  AddASM(100, 200) = "; c

    PRINT ""
    PRINT "PB section:"
    PRINT "  GCD(48, 18) = "; GCD(48, 18)
    PRINT "  GCD(100, 35) = "; GCD(100, 35)

    PRINT ""
    PRINT "Squares:"
    i = 1
    WHILE i <= 10
        PRINT "  "; i; "^2 = "; i * i
        i = i + 1
    WEND

    PRINT ""
    PRINT "Powers of 2:"
    tmp = 1
    WHILE tmp <= 512
        PRINT "  "; tmp
        tmp = tmp * 2
    WEND
    PRINT ""

    PRINT ""
    PRINT "Prime numbers up to 30:"
    LOCAL isPrime AS LONG
    i = 2
    WHILE i <= 30
        isPrime = 1
        j = 2
        WHILE j * j <= i
            IF i MOD j = 0 THEN
                isPrime = 0
                j = i
            END IF
            j = j + 1
        WEND
        IF isPrime = 1 THEN PRINT "  "; i;
        i = i + 1
    WEND
    PRINT ""

    PRINT ""
    PRINT "All language sections executed successfully."

    FUNCTION = 0
END FUNCTION
