pragma solidity ^0.6.1;
contract Hello {
function SayHi() {
assembly {
// assembly code here
}
}
}
assembly {
// this is a comment
/* this is a multiline
* comment
*/
}
let
keyword to declare variables
assembly {
let x := 1
let y // initialized to 0
}
// x and y not visible here
assembly {
let a := 2
let b := 0x03
let c := "hello world"
}
let a, b := f(x)
function callF(uint input) public pure returns(uint x, uint y) {
assembly {
function f(val) -> a, b {
a := add(val, 1)
b := val
}
x, y := f(input)
}
}
else
block
if eq(value, 0) {
value := 3
}
if
, but with more branching optionsdefault
assembly {
switch x
case 0 { x := 1 }
default { x := add(x,1) }
}
break
: exit the Loopcontinue
: skip to next iteration
function lo(uint max) public pure returns(uint result) {
assembly {
for { let i := 0 }
lt(i, 20)
{ i := add(i, 1) } {
if lt(i,3) { continue }
if gt(i, max) { break }
result := add(result,1)
}
}
}
OpCode (Operation Code) is a machine instruction that specifies the operation to be performed - Wikipedia
assembly { codehash := extcodehash(accountAddress) }
Follow the instructions on the readme file of assembly-loop