- To write the assembly inline, use the assembly keyword:
assembly { // assembly code}
- Create local variables in the assembly by using the let keyword. For variables without any assignment, the default value will be assigned:
let xlet y := 2
- Access the variables that are defined outside the assembly directly:
function f(uint x) public { assembly { x := sub(x, 1) }}
Assigning values to variables that point to memory or storage work differently inside solidity assembly. The assignment will only change the pointer and not the data.
- Create a for loop in the assembly just like a regular loop:
assembly { for { let i := 0 } lt(i, 10) { i := add(i, 1) } { y := add(y, 1) }}
- Use the if statement to validate conditions inside ...