Getting Down with ...

by ...

Lesson n:

In high level programming languages, there are a few simple operations to perform basic math. I will define basic math as operations that can be performed with one built-in function that outputs a single value from two or more inputs. In Python, you can add, subtract, multiply, divide, square, find the root, etc. In assembly, your options are much more limited, but any mathematical function is possible using the tools provided.

The syntax of mathematical operations will vary greatly from that of high-level languages like Python. Instead of writing single lines that can represent multiple separate basic mathematical operations, you must perform each operation on a separate line, using the accumulator to return the result of each component. The value of the accumulator can either be fed into the next equation or stored in a variable for later use. The four mathematical operations available in assembly language are Add, Subtract, Multiply, and Divide.

In order to write multi-operation mathematical functions in assembly language, it is important to understand how to break down equations into smaller components that can be calculated by the four provided operations. To do this, it is important to understand the order of operations and know how to apply it.

For example, let’s say you needed to calculate the output of a parabola given an input.

x2 - 3x + 2

In order to write this function in assembly, you must first break down the individual components to create separate equations that only perform one operation.

(x2) - (3x) + 2

Which in Python could be expressed as:

(x * x) - (3 * x) + 2

Now, the equation can be written in a series of linear steps.

a = x * x
b = x * 3
c = a - b
c + 2

Exercises: