HELP.md 21.8 KB
Newer Older
Mart Lubbers's avatar
helpgen  
Mart Lubbers committed
1 2 3 4 5 6 7 8 9 10 11
# SSM Help

## Table of Contents

- [General help](#General)
- [Instructions help](#Instructions)

## General

### Keywords [⭱](#ssm-help)

Mart Lubbers's avatar
Mart Lubbers committed
12
[registers](#registers-) [PC](#PC-) [programcounter](#programcounter-) [SP](#SP-) [stackpointer](#stackpointer-) [MP](#MP-) [markpointer](#markpointer-) [HP](#HP-) [heappointer](#heappointer-) [RR](#RR-) [return register](#return register-) [instruction](#instruction-) [memory](#memory-) [stack](#stack-) [heap](#heap-) [code](#code-) [help](#help-) [syntax](#syntax-) [labels](#labels-) [False](#False-) [True](#True-) 
Mart Lubbers's avatar
helpgen  
Mart Lubbers committed
13 14 15 16 17 18 19 20 21 22
### registers [⭱](#ssm-help)

Eight registers are available, some of which have a specific purpose. A register is private location in a processor, often faster accessible then external memory. Currently the programcounter (PC), stackpointer (SP), markpointer (MP), heappointer (HP), and return register (RR) as well as freely usable scratch registers are available, respectively identified by numbers 0..7. Registers are identified by the name R<x>, where <x> is the register number. Register with a specific purpose are also named with the name indicating their purpose.

### PC [⭱](#ssm-help)

The programcounter (PC) is used to remember what the current next instruction is. It contains the address (i.e. points to) the location of the next instruction. The machine fetches an instruction from the location pointed to by the PC. After each fetch it is automatically updated to point to the next instruction.

### programcounter [⭱](#ssm-help)

Mart Lubbers's avatar
Mart Lubbers committed
23
See [PC](#PC-) 
Mart Lubbers's avatar
helpgen  
Mart Lubbers committed
24 25 26 27 28 29 30

### SP [⭱](#ssm-help)

The stackpointer (SP) is used to push and pop values for usage in expression evaluation. The stack is also used to store variables. These are often accessed via the MP.

### stackpointer [⭱](#ssm-help)

Mart Lubbers's avatar
Mart Lubbers committed
31
See [SP](#SP-) 
Mart Lubbers's avatar
helpgen  
Mart Lubbers committed
32 33 34 35 36 37 38

### MP [⭱](#ssm-help)

The markpointer (MP) is used to access local variables, allocated on the stack. Each variable is accessed using a displacement relative to the MP.

### markpointer [⭱](#ssm-help)

Mart Lubbers's avatar
Mart Lubbers committed
39
See [MP](#MP-) 
Mart Lubbers's avatar
helpgen  
Mart Lubbers committed
40 41 42 43 44 45 46

### HP [⭱](#ssm-help)

The heappointer (HP) is used to remember the next free address of the heap. After every store to the heap, the heappointer is incremented with the size of stored values. 

### heappointer [⭱](#ssm-help)

Mart Lubbers's avatar
Mart Lubbers committed
47
See [HP](#HP-) 
Mart Lubbers's avatar
helpgen  
Mart Lubbers committed
48 49 50 51 52 53 54

### RR [⭱](#ssm-help)

The return register (RR) is used to return a value without placing it on a stack. Strictly seen this is not necessary but a convenience, since values also can be passed via the stack.

### return register [⭱](#ssm-help)

Mart Lubbers's avatar
Mart Lubbers committed
55
See [RR](#RR-) 
Mart Lubbers's avatar
helpgen  
Mart Lubbers committed
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

### instruction [⭱](#ssm-help)

An instruction is an encoding of some operation, executed in the machine. A set of instructions stored in memory is called the code. Some instructions have inline operands, that is, after their location in the code an extra operand is stored, a constant, e.g. in "ldc 1". In pre/post conditions this location is indicated by M[PCpre+1] since it can be found on that location. The behavior of an instruction is both informally described as well as using pre/postcondifitions.

### memory [⭱](#ssm-help)

Memory stores words. A word is an 32 bits integer. Currently only a limited amount of memory words is reserver (2000), this is rather arbitrary, in the future memory size will adapt automatically to the amount needed.

### stack [⭱](#ssm-help)

Stack is the part of memory used to store values needed for evaluating expressions. The stack is located after the code and grows from lower addresses to higher ones.

### heap [⭱](#ssm-help)

Heap is the part of memory used to store composite values. The heap is located after the stack and grows from lower addresses to higher ones.

### code [⭱](#ssm-help)

Code is the part of memory used to store instructions. It starts at address 0.

### help [⭱](#ssm-help)

The Simple Stack Machine Interpreter executes instructions for a hypothetical (and thus simple) machine. See memory, registers, syntax, instruction as starting points for help.

### syntax [⭱](#ssm-help)

Syntax of instructions (as loaded from file) is: (label:)? (instr arg*)?. In other words, an (optional) instruction preceded by an (optional) label and followed by an argument if required. Comment may start with ";" or "//" (Java/C++ style) and ends at the end of the line. This characters are interpreted as start of comment. A label may be used as an argument. Example: "l1: beq l1 ; comment".

### labels [⭱](#ssm-help)

A label is an identifier indicating a position in the code. When loading, the code location of a label is calculated (called resolution). This is done in the user interface of the program and after loading labels are not kept consistent (when adding new instructions for example).

### False [⭱](#ssm-help)

Value False is encoded by a 0.

### True [⭱](#ssm-help)

Value True is encoded by a -1 (all 1 bit pattern 0xFFFFFFFF). However, when testing in the context of a BRF instruction takes place, anything else than 0 is considered to be True.

## Instructions

### Keywords [⭱](#ssm-help)

Mart Lubbers's avatar
Mart Lubbers committed
101
[ldc](#ldc-) [lds](#lds-) [ldms](#ldms-) [sts](#sts-) [stms](#stms-) [ldsa](#ldsa-) [ldl](#ldl-) [ldml](#ldml-) [stl](#stl-) [stml](#stml-) [ldla](#ldla-) [lda](#lda-) [ldma](#ldma-) [ldaa](#ldaa-) [sta](#sta-) [stma](#stma-) [ldr](#ldr-) [ldrr](#ldrr-) [str](#str-) [swp](#swp-) [swpr](#swpr-) [swprr](#swprr-) [ajs](#ajs-) [add](#add-) [mul](#mul-) [sub](#sub-) [div](#div-) [mod](#mod-) [and](#and-) [or](#or-) [xor](#xor-) [eq](#eq-) [ne](#ne-) [lt](#lt-) [le](#le-) [gt](#gt-) [ge](#ge-) [neg](#neg-) [not](#not-) [bsr](#bsr-) [bra](#bra-) [brf](#brf-) [brt](#brt-) [jsr](#jsr-) [ret](#ret-) [link](#link-) [unlink](#unlink-) [nop](#nop-) [halt](#halt-) [trap](#trap-) [annote](#annote-) [ldh](#ldh-) [ldmh](#ldmh-) [sth](#sth-) [stmh](#stmh-) 
Mart Lubbers's avatar
helpgen  
Mart Lubbers committed
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 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833

### ldc [⭱](#ssm-help)

#### Description

Load Constant. Pushes the inline constant on the stack.

#### Pre and postconditions

```
SP_post = SP_pre + 1
M_post[SP_post] = M_pre[PC_pre+1]
```

### lds [⭱](#ssm-help)

#### Description

Load from Stack. Pushes a value relative to the top of the stack.

#### Pre and postconditions

```
SP_post = SP_pre + 1
M_post[SP_post] = M_pre[SP_pre + M_pre[PC_pre+1]]
```

### ldms [⭱](#ssm-help)

#### Description

Load Multiple from Stack. Pushes values relative to the top of the stack. Same as single load variant but second inline parameter is size.

#### Pre and postconditions

```
displ = M_pre[PC_pre + 1]
size = M_pre[PC_pre + 2]
SP_post = SP_pre + size
M_post[SP_post - size + 1 .. SP_post] = M_pre[SP_pre + displ .. SP_pre + displ + size - 1]
```

### sts [⭱](#ssm-help)

#### Description

Store into Stack. Pops a value from the stack and stores it in a location relative to the top of the stack.

#### Pre and postconditions

```
SP_post = SP_pre - 1
M_post[SP_pre + M_pre[PC_pre+1]] = M_pre[SP_pre]
```

### stms [⭱](#ssm-help)

#### Description

Store Multiple into Stack. Pops values from the stack and stores it in a location relative to the top of the stack. Same as single store variant but second inline parameter is size.

#### Pre and postconditions

```
displ = M_pre[PC_pre + 1]
size = M_pre[PC_pre + 2]
SP_post = SP_pre - size
M_post[SP_pre + displ .. SP_pre + displ + size - 1] = M_pre[SP_post + 1 .. SP_post + size]
```

### ldsa [⭱](#ssm-help)

#### Description

Load Stack Address. Pushes the address of a value relative to the stackpointer.

#### Pre and postconditions

```
SP_post = SP_pre + 1
M_post[SP_post] = SP_pre + M_pre[PC_pre+1]
```

### ldl [⭱](#ssm-help)

#### Description

Load Local. Pushes a value relative to the markpointer.

#### Pre and postconditions

```
SP_post = SP_pre + 1
M_post[SP_post] = M_pre[MP_pre + M_pre[PC_pre+1]]
```

### ldml [⭱](#ssm-help)

#### Description

Load Multiple Local. Pushes values relative to the markpointer. Same as single load variant but second inline parameter is size.

#### Pre and postconditions

```
displ = M_pre[PC_pre + 1]
size = M_pre[PC_pre + 2]
SP_post = SP_pre + size
M_post[SP_post - size + 1 .. SP_post] = M_pre[MP_pre + displ .. MP_pre + displ + size - 1]
```

### stl [⭱](#ssm-help)

#### Description

Store Local. Pops a value from the stack and stores it in a location relative to the markpointer.

#### Pre and postconditions

```
SP_post = SP_pre - 1
M_post[MP_pre + M_pre[PC_pre+1]] = M_pre[SP_pre]
```

### stml [⭱](#ssm-help)

#### Description

Store Multiple Local. Pops values from the stack and stores it in a location relative to the markpointer. Same as single store variant but second inline parameter is size.

#### Pre and postconditions

```
displ = M_pre[PC_pre + 1]
size = M_pre[PC_pre + 2]
SP_post = SP_pre - size
M_post[MP_pre + displ .. MP_pre + displ + size - 1] = M_pre[SP_post + 1 .. SP_post + size]
```

### ldla [⭱](#ssm-help)

#### Description

Load Local Address. Pushes the address of a value relative to the markpointer.

#### Pre and postconditions

```
SP_post = SP_pre + 1
M_post[SP_post] = MP_pre + M_pre[PC_pre+1]
```

### lda [⭱](#ssm-help)

#### Description

Load via Address. Dereferencing. Pushes the value pointed to by the value at the top of the stack. The pointer value is offset by a constant offset.

#### Pre and postconditions

```
SP_post = SP_pre
M_post[SP_post] = M_pre[M_pre[SP_pre] + M_pre[PC_pre+1]]
```

### ldma [⭱](#ssm-help)

#### Description

Load Multiple via Address. Pushes values relative to by the value at the top of the stack. Same as single load variant but second inline parameter is size.

#### Pre and postconditions

```
displ = M_pre[PC_pre + 1]
size = M_pre[PC_pre + 2]
SP_post = SP_pre + size - 1
M_post[SP_post - size + 1 .. SP_post] = M_pre[M_pre[SP_pre] + displ .. M_pre[SP_pre] + displ + size - 1]
```

### ldaa [⭱](#ssm-help)

#### Description

Load Address of Address. Pushes the address of a value relative to the address on top of the stack. This instruction effectively adds a constant to the top of the stack.

#### Pre and postconditions

```
SP_post = SP_pre + 1
M_post[SP_post] = M_pre[SP_pre] + M_pre[PC_pre+1]
```

### sta [⭱](#ssm-help)

#### Description

Store via Address. Pops 2 values from the stack and stores the second popped value in the location pointed to by the first. The pointer value is offset by a constant offset.

#### Pre and postconditions

```
SP_post = SP_pre - 2
M_post[M_pre[SP_pre] + M_pre[PC_pre+1]] = M_pre[SP_pre-1]
```

### stma [⭱](#ssm-help)

#### Description

Store Multiple via Address. Pops values from the stack and stores it in a location relative to the value at the top of the stack. Same as single store variant but second inline parameter is size.

#### Pre and postconditions

```
displ = M_pre[PC_pre + 1]
size = M_pre[PC_pre + 2]
SP_post = SP_pre - size - 1
M_post[M_pre[SP_pre] + displ .. M_pre[SP_pre] + displ + size - 1] = M_pre[SP_post + 1 .. SP_post + size]
```

### ldr [⭱](#ssm-help)

#### Description

Load Register. Pushes a value from a register. Registers 0, 1, 2 and 3 are called PC (programcounter), SP (stackpointer), MP (markpointer) and RR (return register) respectively.

#### Pre and postconditions

```
SP_post = SP_pre + 1
M_post[SP_post] = REG_pre[ M_pre[PC_pre+1] ]
```

### ldrr [⭱](#ssm-help)

#### Description

Load Register from Register. Copy the content of the second register to the first. Does not affect the stack.

#### Pre and postconditions

```
REG_post[ M_pre[PC_pre+1] ] = REG_pre[ M_pre[PC_pre+2] ]
```

### str [⭱](#ssm-help)

#### Description

Store Register. Pops a value from the stack and stores it in the specified register. See also ldr.

#### Pre and postconditions

```
SP_post = SP_pre - 1
REG_post[ M_pre[PC_pre+1] ] = M_pre[SP_pre]
```

### swp [⭱](#ssm-help)

#### Description

Swap values. Swaps the 2 topmost values on the stack.

#### Pre and postconditions

```
SP_post = SP_pre
M_post[SP_post] = M_pre[SP_pre-1]
M_post[SP_post-1] = M_pre[SP_pre]
```

### swpr [⭱](#ssm-help)

#### Description

Swap Register. Swaps the content of a register with the top of the stack.

#### Pre and postconditions

```
SP_post = SP_pre
M_post[SP_post] = REG_pre[ M_pre[PC_pre+1] ]
REG_post[ M_pre[PC_pre+1] ] = M_pre[SP_pre]
```

### swprr [⭱](#ssm-help)

#### Description

Swap 2 Registers. Swaps the content of a register with another register.

#### Pre and postconditions

```
REG_post[ M_pre[PC_pre+1] ] = REG_pre[ M_pre[PC_pre+2] ]
REG_post[ M_pre[PC_pre+2] ] = REG_pre[ M_pre[PC_pre+1] ]
```

### ajs [⭱](#ssm-help)

#### Description

Adjust Stack. Adjusts the stackpointer with fixed amount.

#### Pre and postconditions

```
SP_post = SP_pre + M_post[PC_pre+1]
```

### add [⭱](#ssm-help)

#### Description

Addition. Replaces 2 top stack values with the addition of those values.

#### Pre and postconditions

```
SP_post = SP_pre - 1
M_post[SP_post] = M_pre[SP_pre - 1] + M_pre[SP_pre]
```

### mul [⭱](#ssm-help)

#### Description

Multiplication. Replaces 2 top stack values with the multiplication of those values.

#### Pre and postconditions

```
SP_post = SP_pre - 1
M_post[SP_post] = M_pre[SP_pre - 1] * M_pre[SP_pre]
```

### sub [⭱](#ssm-help)

#### Description

Substraction. Replaces 2 top stack values with the subtraction of those values.

#### Pre and postconditions

```
SP_post = SP_pre - 1
M_post[SP_post] = M_pre[SP_pre - 1] - M_pre[SP_pre]
```

### div [⭱](#ssm-help)

#### Description

Division. Replaces 2 top stack values with the division of those values.

#### Pre and postconditions

```
SP_post = SP_pre - 1
M_post[SP_post] = M_pre[SP_pre - 1] / M_pre[SP_pre]
```

### mod [⭱](#ssm-help)

#### Description

Division. Replaces 2 top stack values with the modulo of those values.

#### Pre and postconditions

```
SP_post = SP_pre - 1
M_post[SP_post] = M_pre[SP_pre - 1] % M_pre[SP_pre]
```

### and [⭱](#ssm-help)

#### Description

And. Replaces 2 top stack values with the bitwise and of those values.

#### Pre and postconditions

```
SP_post = SP_pre - 1
M_post[SP_post] = M_pre[SP_pre - 1] & M_pre[SP_pre]
```

### or [⭱](#ssm-help)

#### Description

Or. Replaces 2 top stack values with the bitwise or of those values.

#### Pre and postconditions

```
SP_post = SP_pre - 1
M_post[SP_post] = M_pre[SP_pre - 1] | M_pre[SP_pre]
```

### xor [⭱](#ssm-help)

#### Description

Exclusive Or. Replaces 2 top stack values with the bitwise exclusive or of those values.

#### Pre and postconditions

```
SP_post = SP_pre - 1
M_post[SP_post] = M_pre[SP_pre - 1] ^ M_pre[SP_pre]
```

### eq [⭱](#ssm-help)

#### Description

Test for equal. Replaces 2 top stack values with boolean result of the test. False is encoded as 0, True as 1. Used in combination with brf. This is a variant of cmp combined with beq.

#### Pre and postconditions

```
SP_post = SP_pre - 1
M_post[SP_post] = M_pre[SP_pre - 1] == M_pre[SP_pre]
```

### ne [⭱](#ssm-help)

#### Description

Test for not equal. Replaces 2 top stack values with boolean result of the test. False is encoded as 0, True as 1. Used in combination with brf. This is a variant of cmp combined with bne.

#### Pre and postconditions

```
SP_post = SP_pre - 1
M_post[SP_post] = M_pre[SP_pre - 1] != M_pre[SP_pre]
```

### lt [⭱](#ssm-help)

#### Description

Test for less then. Replaces 2 top stack values with boolean result of the test. False is encoded as 0, True as 1. Used in combination with brf. This is a variant of cmp combined with blt.

#### Pre and postconditions

```
SP_post = SP_pre - 1
M_post[SP_post] = M_pre[SP_pre - 1] < M_pre[SP_pre]
```

### le [⭱](#ssm-help)

#### Description

Test for less or equal. Replaces 2 top stack values with boolean result of the test. False is encoded as 0, True as 1. Used in combination with brf. This is a variant of cmp combined with ble.

#### Pre and postconditions

```
SP_post = SP_pre - 1
M_post[SP_post] = M_pre[SP_pre - 1] <= M_pre[SP_pre]
```

### gt [⭱](#ssm-help)

#### Description

Test for greater then. Replaces 2 top stack values with boolean result of the test. False is encoded as 0, True as 1. Used in combination with brf. This is a variant of cmp combined with bgt.

#### Pre and postconditions

```
SP_post = SP_pre - 1
M_post[SP_post] = M_pre[SP_pre - 1] > M_pre[SP_pre]
```

### ge [⭱](#ssm-help)

#### Description

Test for greater or equal. Replaces 2 top stack values with boolean result of the test. False is encoded as 0, True as 1. Used in combination with brf. This is a variant of cmp combined with bge.

#### Pre and postconditions

```
SP_post = SP_pre - 1
M_post[SP_post] = M_pre[SP_pre - 1] >= M_pre[SP_pre]
```

### neg [⭱](#ssm-help)

#### Description

Negation. Replaces top stack values with the (integer) negative of the value.

#### Pre and postconditions

```
SP_post = SP_pre
M_post[SP_post] = - M_pre[SP_pre]
```

### not [⭱](#ssm-help)

#### Description

Not. Replaces top stack values with the bitwise complement of the value.

#### Pre and postconditions

```
SP_post = SP_pre
M_post[SP_post] = ~ M_pre[SP_pre]
```

### bsr [⭱](#ssm-help)

#### Description

Branch to subroutine. Pushes the PC on the stack and jumps to the subroutine.

#### Pre and postconditions

```
SP_post = SP_pre + 1
M_post[SP_post] = PC_pre + 2
PC_post = PC_pre + M_pre[PC_pre + 1] + 2
```

### bra [⭱](#ssm-help)

#### Description

Branch Allways. Jumps to the destination. Replaces the PC with the destination address.

#### Pre and postconditions

```
PC_post = PC_pre + M_pre[PC_pre + 1] + 2
```

### brf [⭱](#ssm-help)

#### Description

Branch on False. If a False value is on top of the stack, jump to the destination.

#### Pre and postconditions

```
SP_post = SP_pre - 1
PC_post = PC_pre + M_pre[PC_pre + 1] + 2 (if false on top of the stack)
```

### brt [⭱](#ssm-help)

#### Description

Branch on True. If a True value is on top of the stack, jump to the destination.

#### Pre and postconditions

```
SP_post = SP_pre - 1
PC_post = PC_pre + M_pre[PC_pre + 1] + 2 (if true on top of the stack)
```

### jsr [⭱](#ssm-help)

#### Description

Jump to subroutine. Pops a destination from the stack, pushes the PC on the stack and jumps to the destination.

#### Pre and postconditions

```
SP_post = SP_pre
PC_post = M_pre[SP_pre]
M_post[SP_post] = PC_pre + 1
```

### ret [⭱](#ssm-help)

#### Description

Return from subroutine. Pops a previously pushed PC from the stack and jumps to it.

#### Pre and postconditions

```
SP_post = SP_pre - 1
PC_post = M_pre[SP_pre]
```

### link [⭱](#ssm-help)

#### Description

Reserve memory for locals. Convenience instruction combining the push of MP and the adjustment of the SP.

#### Pre and postconditions

```
MP_post = SP_pre  + 1
M_post[MP_post] = MP_pre
SP_post = MP_post + M_pre[PC_pre+1]
```

### unlink [⭱](#ssm-help)

#### Description

Free memory for locals. Convenience instruction combining the push of MP and the adjustment of the SP.

#### Pre and postconditions

```
MP_post = M_pre[MP_pre]
SP_post = MP_pre - 1
```

### nop [⭱](#ssm-help)

#### Description

No operation. Well, guess what...

#### Examples

```
nop
```

### halt [⭱](#ssm-help)

#### Description

Halt execution. Machine stops executing instructions.

#### Examples

```
halt
```

### trap [⭱](#ssm-help)

#### Description

Trap to environment function. Trap invokes a systemcall determined by its argument. Currently, trap supports the following system calls: <ol> <li value="0">Pop the topmost element from the stack and print it as an integer.</li> <li value="1">Pop the topmost element from the stack and print it as a unicode character.</li> <li value="10">Ask the user for an integer input and push it on the stack.</li> <li value="11">Ask the user for a unicode character input and push it on the stack.</li> <li value="12">Ask the user for a sequence of unicode characters input and push the characters on the stack terminated by a null-character.</li> <li value="20">Pop a null-terminated file name from the stack, open the file for reading and push a file pointer on the stack.</li> <li value="21">Pop a null-terminated file name from the stack, open the file for writing and push a file pointer on the stack.</li> <li value="22">Pop a file pointer from the stack, read a character from the file pointed to by the file pointer and push the character on the stack.</li> <li value="23">Pop a character and a file pointer from the stack, write the character to the file pointed to by the file pointer.</li> <li value="24">Pop a file pointer from the stack and close the corresponding file.</li> </ol>

#### Examples

```
ldc 5
trap 0 ; print 5 on output
```

### annote [⭱](#ssm-help)

#### Description

Annotate. A meta instruction (not producing code), annotating the stack display in the user interface with text and color. Annote takes 5 arguments, (1) a register name, (2) a low offset w.r.t. the register (used as starting point for annotating), (3) a high offset, (4) a color, (5) text. Color can be one of {black, blue, cyan, darkGray, gray, green, lightGray, magenta, orange, pink, red, yellow}. Text including spaces need to be enclosed in double quotes. The annote instruction is tied to the preceding (non-meta) instruction and will be performed immediately after the execution of that instruction.

#### Examples

```
annote SP -1 0 red "Pushed constants" ; annote top 2 stack values
```

### ldh [⭱](#ssm-help)

#### Description

Load from Heap. Pushes a value pointed to by the value at the top of the stack. The pointer value is offset by a constant offset.

#### Examples

```
ldc 5
sth
ldh 0
```

### ldmh [⭱](#ssm-help)

#### Description

Load Multiple from Heap. Pushes values pointed to by the value at the top of the stack. The pointer value is offset by a constant offset. Same as single load variant but the second inline parameter is size.

#### Examples

```
ldc 1
ldc 2
ldc 3
stmh 3
ldmh 0 3
```

### sth [⭱](#ssm-help)

#### Description

Store into Heap. Pops 1 value from the stack and stores it into the heap. Pushes the heap address of that value on the stack.

#### Examples

```
ldc 5
sth
```

### stmh [⭱](#ssm-help)

#### Description

Store Multiple into Heap. Pops values from the stack and stores it into the heap, retaining the order of the values. Same as single store variant but the inline parameter is size. Pushes the heap address of the last value on the stack.

#### Examples

```
ldc 1
ldc 2
ldc 3
stmh 3
```