I'm trying to improve my assembly skills and so I'm trying to write a function that allows me to use assembly to read from one memory array variable and write into another memory array variable but 'm having difficulty.
function getArray() public pure returns(uint256[] memory) {
uint256[] memory arrayOne = new uint256[](9);
arrayOne[0] = 1;
arrayOne[1] = 2;
arrayOne[2] = 3;
arrayOne[3] = 4;
arrayOne[4] = 5;
arrayOne[5] = 1;
arrayOne[6] = 1;
arrayOne[7] = 1;
arrayOne[8] = 1;
uint256[] memory arrayTwo = new uint256[](5);
assembly {
let len := mload(arrayTwo)
for
{ let i := 0 }
lt(i, len)
{ i := add(i, 1) }
{
// insert into arrayTwo
}
}
return arrayTwo;
}
I want to loop through arrayOne and insert the first 5 elements into arrayTwo.
My intent is to have arrayTwo = [1,2,3,4,5]