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