Need help implementing a custom sliding window

Hey guys,

I am running against a problem I cant solve.
Lets say I have two matrices matrix A and matrix B, both are 10x10.
Now I want a sliding window, 3x3 to go through matrix A and matrix B and do the following:
So the image is structured, matrix A, matrix B, and what I want the result to be.
image

Next up I take this result matrix sum it up and save it at location e inside of a new matrix.