summaryrefslogtreecommitdiff
path: root/sim/ucsim/docs/syntax.html
blob: cd7fa713cbb4190bcf5fdaf5785b754a5831c0b5 (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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
<html>
  <head>
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <meta http-equiv="content-type" content="text/html; charset=ISO-8859-2">
    <title>Command syntax of &micro;Csim</title>
  </head>
  <body style=" background-color: white;"> Content:
    <ul>
      <li><a href="#syntax">Syntax</a> </li>
      <li><a href="#expr">Expressions</a> </li>
      <li><a href="#redir">Redirection</a> </li>
    </ul>
    
    <h2><a name="syntax">Command syntax of <i>&micro;Csim</i></a></h2>
    
    <i>&micro;Csim</i> uses a very simple command interpreter. Command
    can be entered after <i>&micro;Csim</i> displays the prompt and
    interpreted when ENTER key is pressed. Commands must start with
    the name of the command following parameters. Name of the command
    can be abbreviated if abbreviation is unique. Some commands have
    more than one names.
    
    <p>Syntactically parameters can be a string, bit name, array,
      number or symbol. Interpretation of these syntactical elements
      depends on actual command. </p>
    
    <p>If the command line can not be recognized as a known command, <i>&micro;Csim</i>
      tries to evaluate the command line as an <i>expression</i>. <a href="#expr">See
        below</a> for information about operands and operators which
      can be used in expressions. </p>
    
    <h3><a name="command_name">Command names</a></h3>
    
    Name of the command must be the first word of the command line. It
    is not necessary to enter whole name if abbreviation is
    unique. Help command can be used to check out if a command has
    more names:

    <pre>&gt; <font color="green">help run</font>
run [start [stop]] Go
Names of command: <b>go r run</b>
...
    </pre>

    Some commands just groups other commands. These commands have a
    set of so-called <i>sub-commands</i>. Sub-command must be second
    word in the command line. For example:
    
    <pre>&gt; <font color="green">help set</font>
set <b>subcommand</b>     Set, see `set' command for more help
Names of command: set
long help of set
&gt; <font color="green">set</font>
"set" must be followed by the name of a subcommand
List of subcommands:
<b>set option</b> name|nr value
                   Set value of an option
<b>set error</b> on|off|unset
                   Set value of an error
<b>set memory</b> memory_type address data... or bitspec data
                   Place list of data into memory
<b>set bit</b> bitspec data   Set specified bit(s)
<b>set hardware</b> category params...
                   Set parameters of specified hardware element
    </pre>
    
    <h3>Type of parameters</h3>
    
    <h4><a name="string_type">String type</a></h4>
    
    To distinguish strings and symbols, strings can be surrounded by
    (double) quotes. Quotes can be omitted if command parameter is
    interpreted as string and actual parameter start with a letter (so
    it doesn't look to be a number) and doesn't contain space. Let's
    look an example:
    
    <pre>0&gt; <font color="green">set opt 7 <b>s51&gt;</b></font>
0s51&gt;<font color="green">set opt 7 <b>".s51&gt; "</b></font>
0.s51&gt; 
</pre>

<h4><a name="bit_type">Bit type</a></h4>

If a parameter contains a dot (.) or a colon contained in square
    brackets ([...:...])  it is treated as a bit specification. If
    there is a dot the part before the dot gives the memory address
    and part after the dot gives the bit number. The bracketed form is
    used to specify a range of bits.

<pre>0&gt; <font color="green">dump <b>p1.1</b></font>
      P1.1 0x90 ff 1
0&gt; <font color="green">dump <b>0x80.1</b></font>
      P4.1 0x80 ff 1
0&gt; 
</pre>

<h4><a name="array_type">Array type</a></h4>

Parameters contain [ character are treated as arrays. Arrays can be
    used to specify hardware elements. Array index selects an object
    if more than one exists:

<pre>0&gt; <font color="green">info hw <b>port[0]</b></font>
port[0]
P0    11111111 0xff 255 . (Value in SFR register)
Pin0  11111111 0xff 255 . (Output of outside circuits)
Port0 11111111 0xff 255 . (Value on the port pins)
0&gt; 
</pre>

<h4><a name="number_type">Number type</a></h4>

Some commands accept parameters which in most cases can be
    numbers. Numbers can be entered in C-style form. If the number
    begins with <tt><b>0x</b></tt>
    or <tt><b>0X</b></tt> it is interpreted as a <i>hexadecimal</i> number. As
    extension to C-style, number can be started by <b><span style="font-family: monospace;">0b</span></b>,
    followed by <b><span style="font-family: monospace;">0</span></b> and <b><span
        style="font-family: monospace;">1</span></b> characters. In this case it
    is interpreted as <i>binary</i> number. If it begins with <tt><b>0</b></tt>
    followed by digits it is interpreted as <i>octal</i> number. In
other cases it is interpreted as <i>decimal</i> number.<br>

<h4><a name="symbol_type">Symbol type</a></h4>

    If a command parameter can not be classified in other ways
    (doesn't start with a digit or a quote, doesn't contain dot or [)
    then it will be treated as a <b>symbol</b>. Symbols can be interpreted in several ways.

<h3>Interpretation of parameters</h3>

<h4><a name="address_param">Address parameters</a></h4>

Many commands requires memory addresses as parameters. Addresses can
    be specified using number or symbol type of parameters. Value of
    symbols depends on processor type. For example MCS52 family of
    controllers defines more symbols than MCS51 family.

<h4><a name="number_param">Number, data parameters</a></h4>

When a command expects a number it should get a number. <font color="red">Note</font>,
    that symbols is not converted to number they can be used as address only!

<h4><a name="string_param">String parameters</a></h4>

Strings can be entered without quotes if they are recognized as strings (see
    above) and do not contain spaces.

<h4><a name="data_list_param">Data list parameters</a></h4>

Data list can be any space separated list of numbers and strings. If
    you include a string in the list, it is broken to list of bytes
    where every byte is ASCII code of a string's character.

<pre>&gt; <font color="green">where xram "ab" 0x43</font>
0xf961 61 62 63                abc
&gt; 
</pre>

<h4><a name="memory_param">Memory parameters</a></h4>

Where memory type is expected, name of the memory should be used. Most
    commands accept memory chip and address space too. See <a href="memory.html">memory
      simulation</a> for more information.

<h4><a name="hw_param">Hardware element parameters</a></h4>

Hardware elements can be specified by using arrays, where array name
is name of the element and the array index selects one if more than
one exists.

<h4><a name="bit_param">Bit parameters</a></h4>

Bits can be specified by several ways. One way is using bit type of command
parameter:

    <pre>0&gt; <font color="green">dump 0.2</font>
    0x00000.2               0
0&gt; <font color="green">dump 0xc3.2</font>
    0x000c3.2               1
0&gt; <font color="green">var a_reg rom[0x1000]</font>
0&gt; <font color="green">dump a_reg[7:0]</font>
      0x01000      a_reg           0b11110111 0xf7 '.' 247 ( -9)
0&gt; <font color="green">dump a_reg[5:2]</font>
      0x01000[5:2] a_reg[5:2]      0b--1101-- 0x0d '.'  13 ( -3)
0&gt; <font color="green">var some_bits rom[0x1000][5:2]</font>
0&gt; <font color="green">dump some_bits</font>
      0x01000[5:2] some_bits       0b--1101-- 0x0d '.'  13 ( -3)
0&gt; <font color="green">dump some_bits[4:3]</font>
      0x01000[4:3] a_reg[4:3]      0b---10--- 0x02 '.'   2 ( -2)
0&gt;
</pre>

<p>Note that in the above the <code>[4:3]</code> <em>overrides</em> the
    <code>[5:2]</code> defined for the var and <code>some_bits[4:3]</code>means
    bits 4 through 3 of the value stored at 0x1000. It does <em>not</em> mean
    take the bits defined by the var and then take a subset of those
    bits.  Note also that the output does not tell us we are looking
    at <code>some_bit</code>
    (because we're not) but since we have a var set for the address as a whole
    it does tell us that we are looking at a subset of <code>a_reg</code>.</p>

    <p>In this way, any IRAM or SFR location can be addressed as the above
      example shows.</p>
    
    <p>Other way is using bit address either by value or by symbolic name: </p>
    
    <pre>0&gt; <font color="green">dump ea</font>
     IE0.7 0xa8 00 0
0&gt; <font color="green">dump 34</font>
    0x24.2 0x24 24 1
0&gt; <font color="green">dump 0xc7</font>
   SCON1.7 0xc0 00 0
0&gt; 
    </pre>

    Of course, only addressable bits can be accessed in this way.
    
<hr>

<h2><a name="expr">Expressions</a></h2>

<p>Expressions can be evaluated by <a href="cmd_general.html#expression">expression</a> command. If
first word of the command line is not recognized as a known command,
the command line will be evaluated as an expression and the result
value printed (in decimal):</p>

<pre>0&gt; <font color="green">12*(34+56)</font>
1080
0&gt; 
</pre>
    <h3>Operands</h3>
    Operands of the expressions can be
    <ul>
      <li>number (literal); </li>
      <li>memory (either address space, or memory chip); </li>
      <li>or bit</li>
    </ul>
    
    <h4>Number operands</h4>
    
    Numbers can be entered in decimal, octal (starting with 0 followed
    by a number), or hexadecimal (started with 0x), or binary (started
    with 0b), or ascii code format (letter between apostrophes):

    <pre>0&gt; <font color="green">12</font>
12
0&gt; <font color="green">012</font>
10
0&gt; <font color="green">0x12</font>
18
0&gt; <font color="green">0b010101</font>
21
0&gt; <font color="green">'A'</font>
65
0&gt; 
    </pre>

    Numbers must be integers (floating point is not supported) and not bigger
    than the value which can be stored as <b>long int</b>. Numbers can
    be specified in ascii form too: <b>'a'</b>, result will be ascii
    code of the character. This form accepts C style escapes, for
    example: <b>'\n'</b> or <b>'\033'</b>.

    <h4>Memory operands</h4>
    
    Memory can be an address space location or a memory chip cell. It
    can be specified in following form:

    <pre>name[address]</pre>
    
    where <i>name</i> is the name of the address space or memory chip and <i>address</i>
    is an expression specifying location (index) of the cell.

    <p>Registers in SFR address space can also be specified using pre-defined
      names (symbols) of the registers. </p>
    
    <pre>0&gt; <font color="green">xram[0x543]</font>
67
0&gt; <font color="green">xram_chip[1347]</font>
67
0&gt; <font color="green">rom[12*(34+56)]</font>
56
0&gt; <font color="green">sp</font>
7
0&gt; <font color="green">rom[256*dph+dpl]</font>
88
0&gt; 
    </pre>

    <p>You can assign a symbol (name) to any memory location, this
    name is called variable (see <a href="cmd_memory.html#var">var</a>, and <a href="cmd_general.html#info_variables">info var</a> commands). To specify memory operand, you can use variable name as well:</p>

    <pre>
0&gt; <font color="green">var rom_loc rom[0x1234]</font>
0> <font color="green">info var rom_loc</font>
rom_loc rom[0x1234] = 0xff,255U,255
0&gt; <font color="green">rom_loc</font>
255
0&gt; <font color="green">rom_loc='A'</font>
65
0&gt; <font color="green">expr /c rom_loc</font>
'A'
0&gt;
    </pre>
    
    <p>Value of the memory operand is always a positive integer number.</p>

    <h4>Bit operands</h4>

    Bit operands are evaluated to 0 or 1. Any bit of any memory
    location can be specified as bit using following form:

    <pre>memory.bitnumber</pre>

    where <i>memory</i> is a memory location as a memory operand and <i>bitnumber</i>
    is number of the bit within the specified memory cell specified as an
    expression. Note, that dot (.) is part of the syntax, not an operator.

    <p>Alternatively, name of the bit can be used to specify named SFR bits. </p>
    
    <pre>0&gt; <font color="green">p0.3</font>
1
0&gt; <font color="green">xram[12*(34+56)].9-2</font>
0
0&gt; <font color="green">it0</font>
0
0&gt; 
    </pre>
    
    <h3>Operators</h3>
    <table border="1">
      <tbody>
        <tr>
          <th>Type</th>
          <th>Operator</th>
          <th>Meaning</th>
        </tr>
        <tr>
          <td>Primary</td>
          <td><span style="font-family: monospace;">( )</span></td>
          <td>Group of sub-expressions</td>
        </tr>
        <tr>
          <td>One operand</td>
          <td><span style="font-family: monospace;">+ - &amp; ~ !</span></td>
          <td>Unary plus, minus, address of, bit negate, logical not</td>
        </tr>
        <tr>
          <td rowspan="3" colspan="1">Arithmetic</td>
          <td><span style="font-family: monospace;">* / %</span></td>
          <td>Multiply, divide, modulo</td>
        </tr>
        <tr>
          <td><span style="font-family: monospace;">+ -</span></td>
          <td>Add, subtract</td>
        </tr>
        <tr>
          <td><span style="font-family: monospace;">&lt;&lt; &gt;&gt;</span></td>
          <td>shift left, right</td>
        </tr>
        <tr>
          <td rowspan="2" colspan="1">Logical</td>
          <td><span style="font-family: monospace;">&lt; &gt; &lt;= &gt;= == !=</span></td>
          <td>Comparison of two values</td>
        </tr>
        <tr>
          <td><span style="font-family: monospace;">&amp;&amp; || ^^</span></td>
          <td>Logical and, or, xor</td>
        </tr>
        <tr>
          <td>Bitwise</td>
          <td><span style="font-family: monospace;">&amp; | ^</span></td>
          <td>Bitwise and, or, xor</td>
        </tr>
        <tr>
          <td>Assignment</td>
          <td><span style="font-family: monospace;">= *= /= %= += -= &lt;&lt;=
              &gt;&gt;= &amp;= |= ^=</span></td>
          <td>Assign to</td>
        </tr>
        <tr>
          <td>Increment, decrement</td>
          <td><span style="font-family: monospace;">++ --</span></td>
          <td>Can be used in prefix or postfix style</td>
        </tr>
        <tr>
          <td>Conditional</td>
          <td><span style="font-family: monospace;">?:</span></td>
          <td>Works as in C</td>
        </tr>
        <tr>
          <td>Comma</td>
          <td><span style="font-family: monospace;">,</span></td>
          <td>Evaluates expression in order, results last</td>
        </tr>
      </tbody>
    </table>
    Arithmetic operators and parenthesis work as usual.
    <p>Assignment operator can be used to modify memory cells and bits of the
      cells. Result will be the assigned value. </p>
    <pre>0&gt; <font color="green">p0=23</font>
23
0&gt; <font color="green">i h port[0]</font>
port[0]
P0    00010111 0x17  23 . (Value in SFR register)
Pin0  11111111 0xff 255 . (Output of outside circuits)
Port0 00010111 0x17  23 . (Value on the port pins)
0&gt; <font color="green">p0.0= 0</font>
0
0&gt; <font color="green">i h p[0]</font>
port[0]
P0    00010110 0x16  22 . (Value in SFR register)
Pin0  11111111 0xff 255 . (Output of outside circuits)
Port0 00010110 0x16  22 . (Value on the port pins)
0&gt; <font color="green">xram[256*dph+dpl]= rom[0]</font>
108
0&gt; <font color="green">dump rom 0 0</font>
0x0000 6c                      l
0&gt; <font color="green">dump sfr dph dph</font>
0x83 00                      .
0&gt; <font color="green">dump sfr dpl dpl</font>
0x82 00                      .
0&gt; <font color="green">dump xram 0 0</font>
0x0000 6c                      l
0&gt; <font color="green">0x6c</font>
108
0&gt; <font color="green">dump ea</font>
     IE0.7 0xa8 00 0
0&gt; <font color="green">ea= 1111</font>
1
0&gt; <font color="green">dump ea</font>
     IE0.7 0xa8 80 1
0&gt; 
</pre> When a symbolic name of the SFR is used, it results value of the named
    register not the value of the symbol. "Address of" operator can be used to
    get value of the symbol.
    <pre>0&gt; <font color="green">dpl</font>
0
0&gt; <font color="green">&amp;dpl</font>
130
0&gt; <font color="green">ea</font>
1
0&gt; <font color="green">&amp;ea</font>
175
0&gt; <font color="green">256*dph+dpl</font>
46630
0&gt; <font color="green">&amp;xram[256*dph+dpl]</font>
46630
0&gt; 
</pre>
    <hr>
    <h2><a name="redir">Redirection</a></h2>
    Output of any command can be redirected to a file. Same syntax can be used
    for this as for UNIX shell. The only difference is that <i>&micro;Csim</i>
    doesn't allow to put redirection at the beginning of the command!
    <pre>$ <font color="#118811">ucsim_51 remo.hex</font>
uCsim 0.5.0-pre3, Copyright (C) 1997 Daniel Drotos, Talker Bt.
uCsim comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
55470 words read from remo.hex
0&gt; <font color="#118811">dump &gt;/tmp/rom.dump rom</font>
0&gt; <font color="#118811">quit</font>
$ <font color="#118811">cat /tmp/rom.dump</font>
0x0000 02 01 60 02 00 3c 06 07 ..`..&lt;..
0x0008 08 09 0a 02 2f 6b 0e 0f ..../k..
0x0010 10 11 12 02 00 ac 16 17 ........
0x0018 18 19 1a 1b 1c 1d 1e 1f ........
0x0020 20 21 22 02 01 1c 26 27  !"...&amp;'
0x0028 28 29 2a 32 2c 2d 2e 2f ()*2,-./
0x0030 02 0f a7 02 0e 9c 02 0d ........
0x0038 d2 02 08 41 c0 82 c0 83 ...A....
0x0040 c0 d0 c0 e0 c0 00 a2 90 ........
0x0048 c0 d0 c2 90 78 18 06 30 ....x..0
$ <font color="#118811">ucsim_51 remo.hex</font>
uCsim 0.5.0-pre3, Copyright (C) 1997 Daniel Drotos, Talker Bt.
uCsim comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
55470 words read from remo.hex
0&gt; <font color="#118811">dump rom 0x50 &gt;&gt;/tmp/rom.dump</font>
0&gt; <font color="#118811">quit</font>
$ <font color="#118811">cat /tmp/rom.dump</font>
0x0000 02 01 60 02 00 3c 06 07 ..`..&lt;..
0x0008 08 09 0a 02 2f 6b 0e 0f ..../k..
0x0010 10 11 12 02 00 ac 16 17 ........
0x0018 18 19 1a 1b 1c 1d 1e 1f ........
0x0020 20 21 22 02 01 1c 26 27  !"...&amp;'
0x0028 28 29 2a 32 2c 2d 2e 2f ()*2,-./
0x0030 02 0f a7 02 0e 9c 02 0d ........
0x0038 d2 02 08 41 c0 82 c0 83 ...A....
0x0040 c0 d0 c0 e0 c0 00 a2 90 ........
0x0048 c0 d0 c2 90 78 18 06 30 ....x..0
0x0050 03 4b 20 92 48 30 07 05 .K .H0..
0x0058 c2 07 02 00 9d 30 08 05 .....0..
0x0060 20 93 3a c2 08 90 08 60  .:....`
0x0068 e0 b4 ff 03 02 00 9d 04 ........
0x0070 f0 14 f8 03 03 03 54 1f ......T.
0x0078 90 08 62 25 82 f5 82 e5 ..b%....
0x0080 83 34 00 f5 83 e8 54 07 .4....T.
0x0088 f8 08 74 80 23 d8 fd f8 ..t.#...
0x0090 e0 30 93 07 c8 f4 58 f0 .0....X.
0x0098 02 00 9d 48 f0 d0 d0 92 ...H....
$ 
</pre>
    <hr>
  </body>
</html>