# Basic Operations

#### Math Operations

```solidity
function add(uint x, uint y) external pure returns (uint256) {
        uint ret; 
        assembly {
            ret := add(x,y)
        }
        return ret; 
    }

    function subtract(uint x, uint y) external pure returns (uint256) {
        uint ret; 
        assembly {
            ret := sub(x,y)
        }
        return ret; 
    }

    function multiply(uint x, uint y) external pure returns (uint256) {
        uint ret; 
        assembly {
            ret := mul(x,y)
        }
        return ret; 
    }

		// Note: division rounds down 
    function divide(uint x, uint y) external pure returns (uint256) {
        uint ret; 
        assembly {
            ret := div(x,y)
        }
        return ret; 
   } 

```

#### For Loops

* There are no `else` statements in Yul

```solidity
function isPrime(uint256 x) public pure returns (bool p) {
        p = true;
        assembly {
            let halfX := add(div(x, 2), 1)
            for { let i := 2} lt(i, halfX) { i := add(i,1) } {
                if iszero(mod(x, i)) { // if the modulus of x with is zero, the number is not prime 
                    p := 0 // setting p = 0 equates to false 
                    break
                }

                i := add(i, 1)
            }
        }
    }
```

#### Comparisons

```solidity
function max(uint256 x, uint256 y) external pure returns (uint256 maximum) {
        assembly {
            if lt(x, y) {
                maximum := y
            }
            // there are no else statements in solidity 
            if iszero(lt(x, y)) { // if lt(x, y) is false, then iszero will return true because false is zero in bytecode  
                maximum := x
            }
        }
    } 

// alternatively: 
function max2(uint256 x, uint256 y) external pure returns (uint256 maximum) {
        assembly  {
            if lt(x, y) {
                maximum := y 
            } 
            if gt(x,y) {
                maximum := x
            }
        }
    }
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://thryec.gitbook.io/dev-compedium/ethereum/yul/basic-operations.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
