---
description: The built-in standrad functions library.
---

# stdf - Standard Functions library

#### stdf library

The stdf library is a collection of standard functions within CrateAssembly that provides basic operations for manipulating floating-point values in variables. It includes functions for assigning values, arithmetic addition, subtraction, incrementing, decrementing, and printing values to the console.

**mov Function**

The `mov` function is a fundamental operation in the stdf library for variable management. It is designed to set a specified `value` to a variable named `varname`. The function operates as follows:

* If `varname` does not already exist, `mov` will define a new variable with that name.
* If `varname` does exist, `mov` will modify the existing variable's value to the new `value`.
*   ```assembly
    ; Usage of the mov function in CrateAssembly
    mov varname value ; Sets the value of 'varname' to 'value'
    ```

    **Example Usage:**

    ```assembly
    include stdf ; Includes the stdf functions

    ; Define and set a new floating-point variable 'eax' to 10.5
    mov eax 10.5

    ; Modify the value of existing variable 'eax' to 20.0
    mov eax 20.0
    ```

**add Function**

The add function is another essential operation in the stdf library for variable arithmetic. It allows for the addition of a specified amount to a variable named `varname`. If `varname` does not exist, the add function will return an error, indicating that the variable must be defined before performing arithmetic operations. The function behaves in the following manner:

* The function requires that `varname` already exists.
* It will add the numerical value of `amount` to the current value of `varname`.
* If `varname` does not exist, a DefinitionError is returned.

; Usage of the add function in CrateAssembly add varname amount ; Adds the value of 'amount' to the variable 'varname'

Example Usage:

```assembly
include stdf ; Includes the stdf functions
; Assuming variable 'eax' has been previously defined and set to 10.5
add eax 5.5 ; Adds 5.5 to the current value of 'eax', resulting in 16.0
```

If 'eax' was not previously defined, the add function would return an error:

```assembly
add eax 5.5 ; DefinitionError: eax is not defined
```

**sub Function**

The sub function is a crucial arithmetic operation available in the stdf library for variable arithmetic. It subtracts a specified amount from a variable named varname. Here's how the sub function works:

* The function requires the existence of the variable named varname.
* It will subtract the numerical value of amount from the current value of varname.
* If the variable varname does not exist, a DefinitionError is returned with a specific message.
*   ```assembly
    ; Usage of the sub function in CrateAssembly
    sub varname amount ; Subtracts the value of 'amount' from the variable 'varname'
    ```

    Example Usage:

    ```assembly
    include stdf ; Includes the stdf functions
    ; Let's assume variable 'ebx' has been previously defined and set to 30.0
    sub ebx 5.0 ; Subtracts 5.0 from the current value of 'ebx', resulting in 25.0
    ```

    If 'ebx' was not previously defined, the sub function would return an error:

    ```assembly
    sub ebx 5.0 ; DefinitionError: ebx is not defined
    ```

**inc Function**

The inc function is a convenient operation from the stdf library that allows for incrementing the value of an existing variable by 1. This function is particularly useful for operations where regular increments are needed. Here's how to use the inc function in CrateAssembly:

* The inc function requires that the variable `varname` has already been declared.
* It increments the value of `varname` by 1.
* If `varname` does not exist, an error message `DefinitionError: varname is not defined` is shown.
*   ```assembly
    ; Usage of the inc function in CrateAssembly
    inc varname ; Increments the value of 'varname' by 1
    ```

    Example Usage:

    ```assembly
    include stdf ; Includes the stdf functions
    ; Assuming the variable 'ecx' has been previously defined and set to 5
    inc ecx ; The value of 'ecx' is now 6
    ```

    If 'ecx' was not previously defined, the inc function would result in an error as shown below:

    ```assembly
    inc ecx ; DefinitionError: ecx is not defined
    ```

**dec Function**

The dec function is a simple yet essential operation in the stdf library meant for decreasing the value of an existing variable by 1. Below is a comprehensive guide to using the dec function in CrateAssembly:

* The dec function decrements the value of a predefined variable by 1.
* This function requires the variable varname to be already initialized.
* If the variable varname does not exist, a DefinitionError is triggered, signaling that the variable needs definition.

```
; Usage of the dec function in CrateAssembly 
dec varname ; Decrements the value of 'varname' by 1
```

Example Usage:

```assembly
include stdf ; Includes the stdf functions
; Assuming the variable 'edx' has been defined earlier and its value is set to 8
dec edx ; After execution, the value of 'edx' will be 7
```

If 'edx' was not previously defined, the dec function would return an error:

```assembly
dec edx ; DefinitionError: edx is not defined
```

#### prt Function

The prt function is part of the stdf library in CrateAssembly and it allows you to print the value of a variable or a direct numerical value, be it a floating-point number or an integer. The usage of the prt function is straightforward; it takes a single argument that can be either a variable name or a number.

```
; Usage of the prt function in CrateAssembly
prt varname_or_value ; Prints the value of 'varname' or 'value' to the output
```

Example Usage:

```
include stdf ; Includes the standard function library
; If you have a variable named 'counter' set to a value, for example, 10
prt counter ; This will output the value of 'counter', i.e., 10

; You can also directly print a literal value without defining a variable
prt 42 ; This will output the number 42
```

mul Function

The mul function is a key arithmetic operator provided by the stdf library in CrateAssembly, used for multiplying the value of an existing variable by a given amount. To understand and use the mul function effectively, consider the following points:

* The function requires the existence of the variable referred to as varname.
* The mul function multiplies the current value of varname by the numerical value provided in amount.
* If the variable varname is not already defined in the code, executing the mul function will result in a DefinitionError with the message indicating that varname is not defined.
*   ```assembly
    ; Usage of the mul function in CrateAssembly
    mul varname amount ; Multiplies the variable 'varname' by 'amount'
    ```

    Example Usage:

    ```assembly
    include stdf ; Includes the standard function library

    ; Let's assume the variable 'eax' has already been defined with a value of 10
    mul eax 2 ; After execution, the value of 'eax' will be 20 (10 multiplied by 2)
    ```

    In the event that 'eax' was not previously defined, the mul function would generate an error message:

    ```assembly
    mul eax 2 ; DefinitionError: eax is not defined
    ```

#### div Function

The `div` function is an arithmetic operation included in the CrateAssembly language for dividing the value of an existing variable by a specified amount. The following guidelines will help you understand and use the `div` function:

* Before using the `div` function, the variable referred to as varname must be previously declared and initialized.
* The div function divides the current value of varname by the numerical value given in amount.
* In case varname is not defined in the code, a DefinitionError is triggered with the message "varname is not defined".
*   ```assembly
    ; Usage of the div function in CrateAssembly
    div varname amount ; Divides the value of 'varname' by 'amount'
    ```

    Example Usage:

    ```assembly
    include stdf ; Includes the stdf library for CrateAssembly
    ; Assuming varname 'esi' has been defined and has a value of 20
    div esi 5 ; This will divide 'esi' by 5, resulting in the value 4
    ```

    If 'esi' was not previously defined, the div function would produce an error:

    ```assembly
    div esi 5 ; DefinitionError: esi is not defined
    ```

**elev Function**

The `elev` function is an advanced mathematical operation available in the CrateAssembly language, allowing users to raise a previously defined variable to the power of a given amount. Below are the details on how to use the `elev` function effectively:

* Ensure that the `varname` has already been declared and initialized before using the `elev` function.
* The `elev` function takes two arguments: `varname` and `amount`.
* It raises the value of `varname` to the power specified by `amount`.
* If `varname` is not defined, the function triggers a `DefinitionError`, indicating the variable needs to be declared.

```
; Usage of the elev function in CrateAssembly
elev varname amount ; Raises 'varname' to the power of 'amount'
```

Example Usage:

```
include stdf ; Includes the standard function library in CrateAssembly

; Assuming the variable 'ebx' has been defined earlier with a value of 3
elev ebx 2 ; After execution, 'ebx' will be 9 (3 raised to the power of 2)
```

If 'ebx' was not previously defined, attempting to use the `elev` function would result in an error:

```
elev ebx 2 ; DefinitionError: ebx is not defined
```

**root Function**

The `root` function is a mathematical operation present in the CrateAssembly language that calculates the specified root of a given variable. It's included as part of the standard function library (stdf). To use the `root` function properly, follow these guidelines:

* Before using the `root` function, ensure that the variable (`varname`) has been previously declared and assigned a value.
* The `root` function takes two arguments: `varname` and `amount`, where `amount` represents the degree of the root (e.g., 2 for square root, 3 for cubic root, etc.).
* The function computes the specified root of the variable `varname`.
* If `varname` is not defined, executing the `root` function will result in a `DefinitionError` with a message that `varname` is not defined.
*   ```assembly
    ; Usage of the root function in CrateAssembly
    root varname amount ; Computes the 'amount'-degree root of 'varname'
    ```

    Example Usage:

    ```assembly
    include stdf ; Includes the standard function library
    ; Assuming the variable 'ecx' is defined with a value of 16
    root ecx 2 ; This will calculate the square root of 'ecx', setting it to 4
    ```

    In the case where 'ecx' is not defined, you would encounter an error like so:

    ```assembly
    root ecx 2 ; DefinitionError: ecx is not defined
    ```
