Tier 1

Stack and Math operations

This is very basic term you need to know of to start the adventure with low-level EMC. Don't worry if you don't understand it the first time. You can also learn about it in various programming guidebooks. If you're familiar with it you can omit this section.

Stack is organisation of data that accepts two basic types of operations:

The first one is used to store given value on top of the stack. Succesive values will be stored always on top of the stack. The second one removes element from top of the stack and retrieves its value.

The basic rule of stack is: what you pushed the first will be popped as the last also known as FILO. The stack is used basically to remember the place in the script and retrieve it later (calling sub-routines) and also in calculating math expressions. Additionally stack provides some space for data which can be used as a space for function arguments or local variables. I guess that this sounds terrible but be patient. I will try to describe these terms one by one across the guide.

There are several commands to work on stack in EMC, but let's start from most simple:

With these commands you can calculate almost everything. The types of math operations are add, subtract, multiply and divide. Note that the Eval will pop two values from the stack, perform an action, then push the result. The False, Neg, Not works on one value only. This part of script adds two numbers: 450 and 125. Note that I use operation name instead of Eval in this guide.
  1. Push 450
  2. Push 125
  3. Add

This one calculates more complicated phrase: (60 * 5) / (10 + 5)

  1. Push 60
  2. Push 5
  3. Multiply
  4. Push 10
  5. Push 5
  6. Add
  7. Divide
In this example division is performed on results of previous operations. Note that you must provide arguments in reverse order because of the FILO rule (add, multiply are simetric). Simply? If so you can proceed to next section. If not then don't worry. This guide is too small to provide all important informations. You could refer to any programming book or wait for high-level compiler for EMC...