-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAssembly.sol
53 lines (45 loc) · 1022 Bytes
/
Assembly.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
pragma solidity ^0.4.0;
contract Assembly {
function nativeLoops() public returns (uint _r) {
for(uint i = 0; i < 10; i++) {
_r++;
}
}
function asmLoops() public returns (uint _r) {
assembly {
let i := 0
loop:
i := add(i, 1)
_r := add(_r, 1)
jumpi(loop, lt(i, 10))
}
}
function inlineAsmLoops() public returns (uint _r) {
assembly {
0 // i
10 // max
loop:
// i := add(i, 1)
dup2
1
add
swap2
pop
// _r := add(_r, 1)
dup3
1
add
swap3
pop
// lt(i, 10)
dup1
dup3
lt
// jumpi(loop, lt(i, 10))
loop
jumpi
pop
pop
}
}
}