-
Notifications
You must be signed in to change notification settings - Fork 85
Expand file tree
/
Copy pathAssembly.sol
More file actions
59 lines (53 loc) · 1.03 KB
/
Assembly.sol
File metadata and controls
59 lines (53 loc) · 1.03 KB
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
54
55
56
57
58
59
pragma solidity ^0.4.26;
contract Assembly {
function assemblyLabels() {
assembly {
let n := calldataload(4)
let a := 1
let b := a
loop:
jumpi(loopend, eq(n, 0))
a add swap1
n := sub(n, 1)
jump(loop)
loopend:
mstore(0, a)
return(0, 0x20)
}
assembly{
let x := 8
jump(two)
one:
// Here the stack height is 2 (because we pushed x and 7),
// but the assembler thinks it is 1 because it reads
// from top to bottom.
// Accessing the stack variable x here will lead to errors.
x := 9
jump(three)
two:
7 // push something onto the stack
jump(one)
three:
}
}
}
contract MultipleAssemblyAssignment {
function foo() public pure {
assembly {
function bar() -> a, b {
b : = 2
a := 1
b := 2
}
let i, j := bar()
}
}
}
contract AssemblyStackAssignment {
function f() public {
assembly {
4 =: y
4 = : y
}
}
}