1
uint[2] testStorage;
    
    function assemblyStorage() public  returns (uint a, uint b){
       testStorage[0] = 5;
       testStorage[1] = 10;
       uint[2] memory testMemory = testStorage;
       assembly {
           a:=mload(0x80)
           b:=mload(add(0x80, 32))
       }
    }

I do the following. Now, why does a and b return both 0? instead of 5, 10 ? It got me curious since storage array should be copied to memory..

So, the actual place where 5, and 10 reside is mload(add(0x80, 64)) and mload(add(0x80, 96). Any idea why they are not at 0x80 and add(0x80, 32) since initial memory place is 0x80 ?

2
  • 2
    From this and all your previous questions it seems better to read the compiler source directly. Many compiler details aren't published because they may change in future versions and developers don't want people to assume them will be maintained. In this case the free memory pointer may be updated for any reason before you use it, assuming that it will be at 0x80 is wrong. If you load the function in remix and do a step by step it will show where the free pointer is updated, for the exact reason you will have to read the compiler bytecode generator. – Ismael Oct 3 '20 at 14:54
  • Thanks Ismael, could you look into this ? ethereum.stackexchange.com/questions/88025/… – Nika Kurashvili Oct 3 '20 at 21:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.