raz / test / err / AsmNameWhere.raz

83 lines · 1.0 KiB · raw · history · last change a072a400

1module AsmNameWhere;
2(* A procedure or a variable stands for its address only in call p,
3 jmp p and lea r, [v]; a type, a constant or an unknown name is no
4 procedure, nor is C's, and a label is only for a jump *)
5import SYSTEM;
6
7type T = I64;
8const K = 64;
9var g: I64;
10extern proc puts(s: ^U8): I32;
11
12proc p;
13begin
14end;
15
16proc movName;
17code
18 mov rax, p;
19 ret;
20end movName;
21
22proc load;
23code
24 mov rax, [g];
25 ret;
26end load;
27
28proc condJump;
29code
30 jz p;
31 ret;
32end condJump;
33
34proc offset;
35code
36 lea rax, [g + 8];
37 ret;
38end offset;
39
40proc callType;
41code
42 call T;
43 ret;
44end callType;
45
46proc callConst;
47code
48 call K;
49 ret;
50end callConst;
51
52proc callUnknown;
53code
54 call nowhere;
55 ret;
56end callUnknown;
57
58proc callC;
59code
60 call puts;
61 ret;
62end callC;
63
64proc leaLabel;
65code
66 here:
67 lea rax, [here];
68 ret;
69end leaLabel;
70
71(* a constant still stands where a number does *)
72proc constant: I64;
73code
74 mov rax, K;
75 ret;
76end constant;
77
78proc main*;
79begin
80 g := constant();
81end;
82
83end AsmNameWhere.