aboutsummaryrefslogtreecommitdiff
path: root/doc/sml_language.txt
blob: e7d804e6cdfe7533511a88ccca6d8a6942218ba2 (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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
-= Overview

This document describes language used by cryptrobber and encrypt programs.
Further this language will be referenced as SML (Stack Machine Language).
"Strans" binary stack translator and "Smack" macroprocessor are used for
translating SML program into ELF executable file. This document DOES NOT
describe low level realisation of SML programs. For more information about
methods envolved into this process you can refer to the "Threaded code" and
"Call stack" topics.

SML is a standard stack language. Every word (SML function) is executed in
postfix notation. Even SML numbers are treated as words. For example:

    4 5 + sys_write

"4", "5", "+", "sys_write" are SML words. First, executing "4" will push
nubmer 4 into the stack. Executing "5" will push number 5 into stack.
Executing "+" will pop two numbers from stack (4 and 5), summarize them
and push the result into stack (9). Executing "sys_write" will pop number
from the stack (9) and print it.

Further text will describe all basic SML macros and words in details.
" filename ", * macro *, / word / designations are used to distinguish
between different entities.

-= IA32 macros and words

" macro.sts "

* next *
Finishes assembler word description.

* defasm *
Begins assembler word description.

* defword *
Begins standard SML word description.

* defconst *
Describes constant number SML word.

* defarr *
Describes number array SML word.

* defvar *
Describes number variable SML word.

* as *
Links the name with the top value from stack.

* literal *
Used for transparent translation of numbers. It is a part of
"Smack" macroprocessor, so there is no need to call it expicitly.

* set_entry *
Defines ELF executable entry point.

* if *, * fi *, * else *
These macros are used to describe conditional block.

* do *, * untilod *, * until *, * od *
These macros are used to describe conditional loop block.

" core.sts "

/ docol /
SML word interpreter. It is used by "defword" macro to include in every
SML word header for it's execution.

/ exit /
Finishes SML word execution.

/ lit /
SML number interpreter. It is used by "literal" macro.

" stack.sts "

/ top /
Pushes the address of top of stack.

/ ref /
Pops the number of chosen stack element and pushes the address
of this element.

/ get /
Pops the number of chosen stack element and pushes its value.

/ set /
Pops the value and the number of chosen stack element and changes
the value of this element.

/ drop /
Pops the top stack element.

/ dup /
Pushes the copy of the top stack element.

/ over /
Pushes the copy of stack element over the top stack element.

/ swap /
Swaps two top stack elements.

" branch.sts "

/ branch /
Changes the execution flow to the chosen address.

/ 0branch /
Conditional branch. Changes the execution flow to the chosen address
but only if the value of the top stack element is zero.

" memory.sts "

/ @ /
Replaces the address on top of stack by its value in memory.

/ ! /
Pops the address and the value from stack. Assigns this value to memory
referenced by the chosen address.

" math.sts "

/ + /
Adds two numbers from stack and pushes the result.

/ - /
Subtracts two numbers from stack and pushes the result.

/ mul /
Multiplies two numbers from stack and pushes the result.

/ div /
Divides two numbers from stack and pushes the result.

/ mod /
Divides two numbers from stack and pushes the modulo.

/ = /
Compares two numbers from stack for equality and pushes the result.

/ != /
Compares two numbers from stack for inequality and pushes the result.

/ < /
Compares two numbers from stack. Pushes "1" if the first
is less than the second.

/ > /
Compares two numbers from stack. Pushes "1" if the first
is greater than the second.

" bitwise.sts "

/ xor /
Pops two numbers, applies XOR operation to them and pushes the result.

/ and /
Pops two numbers, applies AND operation to them and pushes the result.

/ shr /
Pops the counter and the value. Shifts right the value with the counter and
pushes the result.

/ shl /
Pops the counter and the value. Shifts left the value with the counter and
pushes the result.