I know that: return(p, s): end execution, return data mem[p…(p+s)).
I want to return something in memory but not a multiple of bytes32. For example, I want to return 1 byte:
pragma solidity 0.8.20;
contract Adder {
function add(uint a, uint b) public pure returns (uint8) {
assembly {
mstore(0x0, add(a, b))
return(0x0, 8)
}
}
function test() public pure returns(uint8){
return add(1,2);
}
}
But when I call add(1,2) and test() in Remix, there is something wrong:
Failed to decode output: Error: data out-of-bounds (length=8, offset=32, code=BUFFER_OVERRUN, version=abi/5.7.0)
The doc doesn't say we should use a multiple of bytes32. 1 byte is okay in theory? But What happened?