inline_assembly.sol 679 B

123456789101112131415161718192021222324252627
  1. contract foo {
  2. struct test_stru {
  3. uint256 a;
  4. uint256 b;
  5. }
  6. function bar(uint64 a) public pure returns (uint64 ret) {
  7. uint64 b = 6;
  8. uint64[] memory vec;
  9. vec.push(4);
  10. string str = "cafe";
  11. test_stru tts = test_stru({a: 1, b: 2});
  12. assembly {
  13. // The following statements modify variables directly
  14. a := add(a, 3)
  15. b := mul(b, 2)
  16. ret := sub(a, b)
  17. // The following modify the reference address
  18. str := 5
  19. vec := 6
  20. tts := 7
  21. }
  22. // Any access to 'str', 'vec' or 'tts' here may crash the program.
  23. }
  24. }