summaryrefslogtreecommitdiff
path: root/04b/in04b
blob: c9a471b8dd5b8975fc41ff5a34010857247dbe09 (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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
; declaration:
;     global <name>
;     local <name>
;     argument <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>, ...)
;     return <rvalue>
;     string <str>
;     byte <number>
; term:
;     <var>
;     .<label>
;     <number>
; number:
;     'c
;     12345
;     0xabc
; lvalue:
;     <var>
;     *1<var> / *2<var> / *4<var> / *8<var>
; rvalue:
;     <term>
;     &<var>
;     *1<var> / *2<var> / *4<var> / *8<var>
;     ~<term>
;     <function>(<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(46) ; hello

global x
global y ;123
global z
:test
function
	local eee
	local fff
	local ggg
	return test2(eee, 0x223, ggg)
	
:test2
function
	return -123
	
:syscall
function
	; ...
	byte 0x0f
	byte 0x05

:strlen
function
	argument s
	local len
	local c
	local p
	len = 0
	:strlen_loop
	p = s + len
	c = *1 p
	if c == 0 goto strlen_loop_end
	len += 1
	goto strlen_loop
	:strlen_loop_end
	return len

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

:puts
function
	argument s
	local len
	len = strlen(s)
	syscall(1, 1, s, len)
	return

:main
function
	puts(.str_hello_world)
	syscall(0x3c, 0)
:str_hello_world
string Hello, world!
byte 10
byte 0

:f
function
	argument x
	argument y
	local v
	local p
	v = *4x
	p = *8y
	*4p = v
	if v == 0 goto something
	*1p = v + 1
	v = *2p
	return v
	:something
	v = *4p
	return v