' CPU Identification via CPUID instruction
#COMPILE EXE
#DIM ALL

FUNCTION PBMAIN() AS LONG
    LOCAL v1 AS LONG, v2 AS LONG, v3 AS LONG
    LOCAL v4 AS LONG, v5 AS LONG, v6 AS LONG
    LOCAL f1 AS LONG, f2 AS LONG
    LOCAL s AS STRING
    LOCAL family AS LONG, model AS LONG, stepping AS LONG

    #ASM
        xor eax, eax
        cpuid
        mov %v1, ebx
        mov %v2, ecx
        mov %v3, edx
    #ENDASM

    s = CHR$(v1 AND &HFF) + CHR$((v1 SHR 8) AND &HFF)
    s = s + CHR$((v1 SHR 16) AND &HFF) + CHR$((v1 SHR 24) AND &HFF)
    s = s + CHR$(v3 AND &HFF) + CHR$((v3 SHR 8) AND &HFF)
    s = s + CHR$((v3 SHR 16) AND &HFF) + CHR$((v3 SHR 24) AND &HFF)
    s = s + CHR$(v2 AND &HFF) + CHR$((v2 SHR 8) AND &HFF)
    s = s + CHR$((v2 SHR 16) AND &HFF) + CHR$((v2 SHR 24) AND &HFF)

    PRINT "Vendor: "; s

    #ASM
        mov eax, 1
        cpuid
        mov %v4, eax
        mov %f1, ecx
        mov %f2, edx
    #ENDASM

    stepping = v4 AND &H0F
    model = (v4 SHR 4) AND &H0F
    family = (v4 SHR 8) AND &H0F

    PRINT "Family: "; family; "  Model: "; model; "  Stepping: "; stepping

    PRINT "Features (ECX):"
    IF (f1 AND 1) THEN PRINT "  SSE3: Yes" ELSE PRINT "  SSE3: No"
    IF (f1 AND (1 SHR 9)) THEN PRINT "  SSSE3: Yes" ELSE PRINT "  SSSE3: No"
    IF (f1 AND (1 SHR 19)) THEN PRINT "  SSE4.1: Yes" ELSE PRINT "  SSE4.1: No"
    IF (f1 AND (1 SHR 20)) THEN PRINT "  SSE4.2: Yes" ELSE PRINT "  SSE4.2: No"
    IF (f1 AND (1 SHR 23)) THEN PRINT "  POPCNT: Yes" ELSE PRINT "  POPCNT: No"
    IF (f1 AND (1 SHR 25)) THEN PRINT "  AES: Yes" ELSE PRINT "  AES: No"

    PRINT "Features (EDX):"
    IF (f2 AND (1 SHR 23)) THEN PRINT "  MMX: Yes" ELSE PRINT "  MMX: No"
    IF (f2 AND (1 SHR 25)) THEN PRINT "  SSE: Yes" ELSE PRINT "  SSE: No"
    IF (f2 AND (1 SHR 26)) THEN PRINT "  SSE2: Yes" ELSE PRINT "  SSE2: No"
    IF (f2 AND (1 SHR 28)) THEN PRINT "  HTT: Yes" ELSE PRINT "  HTT: No"

    FUNCTION = 0
END FUNCTION
