Refactor memory I/O into separate module

Signed-off-by: Claudio Matsuoka <cmatsuoka@gmail.com>