Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- contract InstructionalAssemblyDemo {
- function assemblyLoop() public view returns (uint result) {
- assembly {
- // i = 0
- let i := 0
- loop:
- // result += i
- result := add(result, i)
- // i++
- i := add(i, 1)
- // if (i < 10) loop again
- jumpi(loop, lt(i, 10))
- }
- }
- function instrAssemblyLoop() public view returns (uint result) {
- assembly {
- // i = 0
- 0
- loop:
- // result += i
- // make a copy of result
- dup2
- // make a copy of i
- dup2
- // add them together
- add
- // assign the result of op to result
- swap2
- // remove the leftovers
- pop
- // i++
- 1
- add
- // if (i < 10) loop again
- // push constant 10 to the stack
- 10
- // push i to the top of stack
- dup2
- // i < 10
- lt
- // push the tag to top of the stack
- loop
- // jumpi(loop, lt(i, 10))
- jumpi
- pop
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement