summaryrefslogtreecommitdiff
path: root/04b/in04b
blob: 06da7231dff65fb1cbf93db0985ce0c6a0906866 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
; types: char, short, int, long, *type
; declaration:
;     global <type> <name>
;     local  <type> <name>
;     :<label>
; statement:
;     <declaration>
;     if <term> <==/</>/>=/<=/!=> <term> goto <label>   NOTE: this uses signed comparisons
;     goto <label>
;     <lvalue> = <rvalue>
;     <lvalue> += <rvalue>
;     <lvalue> -= <rvalue>
;     <function>(<term>, <term>, ...)
;     syscall(<term>, <term>, ...)
;     return <rvalue>
;     byte <number>
; term:
;     <var>
;     <number>
; number:
;     'c
;     12345
;     0xabc
; lvalue:
;     <var>
;     *<var>
;     <var>[<term>]
; rvalue:
;     `<string>`
;     <var>
;     &<var>
;     *<var>
;     <var>[<term>]
;     ~<var>
;     <function>(<term>, <term>, ...)
;     syscall(<term>, <term>, ...)
;     <term> + <term>
;     <term> - <term>
;    NOTE: *, /, % are signed (imul and idiv)
;     <term> * <term>
;     <term> / <term>
;     <term> % <term>
;     <term> & <term>
;     <term> | <term>
;     <term> ^ <term>
;     <term> < <term>  (left shift)
;     <term> > <term>  (unsigned right shift)

main() ; hello

global char x
global short y ;123
global long z

:strlen
function
	argument *char s
	local long len
	local char c
	len = 0
	:strlen_loop
	c = s[len]
	if c == 0 goto strlen_loop_end
	len += 1
	goto strlen_loop
	:strlen_loop_end
	return len

:putc
function
	argument char c
	local *char p
	p = &c
	syscall(1, 1, p, 1, 0, 0, 0, 0)
	return

:puts
function
	argument *char s
	local long len
	len = strlen(s)
	syscall(1, 1, s, len, 0, 0, 0, 0)
	return

:main
function
	local *char hello
	hello = `Hello, world!
`
	puts(hello)
	syscall(0x3c, 0, 0, 0, 0, 0, 0, 0)


:f
function
	argument *long x
	argument *long y
	local long v
	local *long p
	v = *x
	p = *y
	*p = v
	if v == 0 goto something
	p[1] = v + 1
	return p[2]
	:something
	return p[1]