you need to retrieve the value in the slot, then use logical operations to change the bits corresponding to each variable and finally write it back to the slot
sorry. was writing this out of the top of my head and didn't do a second check. the masking for blockTimestampLast is wrong.
The idea is to AND the value in the slot with a mask to set the variable to all 0's and then slh() then new value and ADD them together.
masked := and(sload(blockTimestampLast.slot), sub(exp(2, 32), 1)) does the opposite of the intended (144 0's and 32 1's)
it should be : masked := and(sload(blockTimestampLast.slot), shl(sub(exp(2, 144), 1), 32)) 144 1's and 32 0's
Thanks I compile to yul, analyse the result and update my code to match and it's work
assembly {
// update reserve0
let value := sload(reserve0.slot)
let mask := 0xffffffffffffffffffffffffffff
// uint256 to uint112
let bal0 := and(balance0, mask)
let bal1 := and(balance1, mask)
value := and(value, not(mask))
let result := or(value, and(bal0, mask))
sstore(reserve0.slot, result)
// update reserve1 (the slot remains the same)
value := sload(reserve0.slot)
mask := 0xffffffffffffffffffffffffffff0000000000000000000000000000
let toInsert := shl(112, bal1)
value := and(value, not(mask))
result := or(value, and(toInsert, mask))
sstore(reserve1.slot, result)
}