Types
Yul has only one type - the 32-bit word, or the 256 bits that we’re used to seeing in Solidity.
Yul can also take in hex values, but will output them as decimals, since we are casting them as uint256
Strings are not naturally a bytes32, so we cannot assign values to a string in memory in Yul.
Calling this function will return an out of gas error, since you’re essentially trying to assign “hello world” to the pointer storing the location of the string in memory
We have to change the string’s data type to bytes32, in order for it to be stored in the stack so that Yul can access it. (bytes32 is always stored on the stack)
To make the output a readable string, we have to cast it using:
string(abi.encode(myString))
The max size of the string you can assign to a variable in Yul is 32 bytes, anything larger will return a compiler error
32 bytes is the only type in Yul, and Solidity will just enforce an interpretation based on the value type its being assigned to.
If we change the variable to an address, it will return
0x0....001 = address(1)
Last updated