raz / examples / Cpu.raz

32 lines · 690 B · raw · history · last change 264716cb

1(* A code procedure: machine code written as bytes, called like any
2 other procedure. cpuid's vendor string, from leaf 0. *)
3module Cpu;
4import Out;
5import SYSTEM;
6
7(* cpuid leaf 0: puts the 12 bytes of the vendor in buf, rdi. *)
8proc vendor(buf: ^U8);
9code
10 push rbx;
11 mov r8, rdi;
12 xor eax, eax;
13 cpuid;
14 mov [r8], ebx;
15 mov [r8 + 4], edx;
16 mov [r8 + 8], ecx;
17 pop rbx;
18 ret;
19end vendor;
20
21proc main*;
22var buf: [12]U8; i: INT; ok: BOOL;
23begin
24 vendor(SYSTEM.ADR(buf[0]));
25 ok := true;
26 for i := 0 to 11 do
27 if (buf[i] < ' ') or (buf[i] > '~') then ok := false; end;
28 end;
29 if ok then Out.str("vendor is printable\n"); end;
30end;
31
32end Cpu.