Use your imagination and creativity
Make a flow chart of the steps you think you'll need
Something like:
1) read port b
2) keep only the lowest 4 inputs using a .... instuction with constant ????
4) store the result in 'Operand_A'
5) read port b
6) keep only the highst 4 inputs using a .... instuction with constant ????
7) divide by y so that the input comes in the LSB
8) store the result in 'Operand_B'
9) Add 'Operand_A' to 'Operand_B'
Give us some proposition for the ...., ????, y, remove unnecessary steps, add the ones I forgot, ...
Writing code is for 95% imagination and creativity, obviously you don't have it yet.
Good luck