Hi I'm trying to make a function in assembly inline with following purpose:
Given: An array in the blockchain with names (= bytes32[] _documentHashes).
Asked: Find which indexes are equal to the name that I search (= bytes32 _searchHash) and return them in an array (= uint[] result)
I have the following code, with some comment to clarify my logic. Following Topic has helped me to produce this code:
function arrMke() public{ // Some test data
bytes32[] arrMke;
arrMke.push(0X10);
arrMke.push(0X20);
arrMke.push(0x10);
arrMke.push(0X40);
uint[] arrResult = search(arrMke,0X10);
}
function search(bytes32[] _documentHashes, bytes32 _searchHash) public returns (uint[] result){
assembly {
let len := mload(_documentHashes) // Load the length (first 32 bytes)
let counter := 0 //count each time data in the _documentHashes == _searchHash
result := mload(0x40) // 0x40 is the address where next free memory slot is stored in Solidity.
let i := 0 // uint i for the loop
loop: //start loop
let docHash := mload(add(_documentHashes, add(0x20, mul(i, 0x20)))) // docHash = _documentHashes[i], data offset = 0x20 (1st 32 is reserved for size) & i*32 to pickup the right index
if eq(docHash, _searchHash) { // condition if(docHash == _searchHash)
counter := add(counter,1) // increment counter by 1
mstore(add(result, 0x20), counter) // (re)Set size of the result array each time the condtion is true
mstore(add(result, add(0x20, mul(counter, 0x20))), i) // add data to the array, data offset = 0x20 (1st 32 is reserved for size) & i*32 to pickup the right index
}
i := add(i,1) // increment for loop
jumpi(loop, lt(i,len)) // stop loop when the lenght of _documenthashes is reached
mstore(0x40, add(result, add(0x20, mul(counter, 0x20)))) // Update/return the result array ofsset + length of the data (=i*32)
}
}
Problem:
- I don't get the debugger in remix running. The "Solidity locals" screen is empty:
- uint[] arrResult = search(0x0,arrMke,0X10); does'nt want to compile:
- Question:
1) How can I watch (see the data in) my variabeles, especially uint[] result? Because I'm not sure if my assemblercode is correct at all. 2) Why do I get this compile error & how can I fix it?
Thanks for your help!
Tshy