# 03 - Return42

**Goal:** Return the number `42` from Yul.

{% code title="Return42.t.sol" %}
```solidity
// SPDX-License-Identifier: AGPL-3.0-or-later
pragma solidity ^0.8.13;

import {Test, console} from "forge-std/Test.sol";
import {Return42} from "../src/Return42.sol";

contract Return42Test is Test {
    Return42 public c;

    function setUp() public {
        c = new Return42();
    }

    function test_Return42() public {
        uint256 r = c.main();
        assertEq(r, 42);
    }
}

```
{% endcode %}

Returning an integer uses the same mechanism as returning a bool, but with a different value. We store the 256-bit representation of 42 in memory, then return 32 bytes. The number 42 (0x2A in hex) will be padded to 32 bytes (meaning 42 in the lowest bits and zeros elsewhere).

{% code title="Return42.sol" %}
```solidity
// SPDX-License-Identifier: AGPL-3.0-or-later
pragma solidity ^0.8.13;

contract Return42 {

  function main() external pure returns (uint256) {
      assembly {
          // Store 42 at memory position 0
          mstore(0, 42)
          // Return 32 bytes from memory position 0 (the value 42)
          return(0, 32)
      }
  }
}
```
{% endcode %}

**Explanation:** We use `mstore(0, 42)` to place the value 42 at memory location 0. Then `return(0, 32)` sends the 32-byte value back. The receiving side will interpret those 32 bytes as a `uint256` equal to 42.

Run test:

```bash
forge test --mp test/Return42.t.sol -vvvv
```

<figure><img src="https://223316867-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MWVtlSxURaW2QQu6RU5%2Fuploads%2F5aHGjZ1uOVNT7DBSrZKw%2Fimage.png?alt=media&#x26;token=e55bb9a0-47e1-4879-a5bb-7dd44dcde524" alt=""><figcaption></figcaption></figure>
