setMem :: Int -> Int32 -> MipsEnv ()
setMem ta tv = do
  mipsEnv <- get
  let
    fi  = fromIntegral :: Int32 -> Word8
    mem = memory mipsEnv
    regsI = intRegisters mipsEnv
    regsF = floatRegisters mipsEnv
    r3  = fi $ tv `mod` (1 `shift` 8 )                 -- least significant
    r2  = fi $ (tv `shift` (-8)) `mod` (1 `shift` 8)
    r1  = fi $ (tv `shift` (-8*2)) `mod` (1 `shift` 8)
    r0  = fi $ (tv `shift` (-8*3)) `mod` (1 `shift` 8)
    in do
    put mipsEnv { intRegisters = regsI,
                floatRegisters = regsF,
                memory = ((take ta mem) ++ [r0,r1,r2,r3] ++ (drop (ta+4) mem)) }
setMem :: Int -> Int32 -> MipsEnv ()
setMem ta tv = do
  mipsEnv <- get
  let
    fi  = fromIntegral :: Int32 -> Word8
    mem = memory mipsEnv
    regsI = intRegisters mipsEnv
    regsF = floatRegisters mipsEnv
    r3  = fi $ tv `mod` (1 `shift` 8 )                 -- least significant
    r2  = fi $ (tv `shift` (-8)) `mod` (1 `shift` 8)
    r1  = fi $ (tv `shift` (-8*2)) `mod` (1 `shift` 8)
    r0  = fi $ (tv `shift` (-8*3)) `mod` (1 `shift` 8)
    in do
    put mipsEnv { intRegisters = regsI,
                floatRegisters = regsF,
                memory = ((take ta mem) ++ [r0,r1,r2,r3] ++ (drop (ta+4) mem)) }
setMem ta tv = do
  mipsEnv <- get
  let
    fi  = fromIntegral :: Int32 -> Word8
    mem = memory mipsEnv
    regsI = intRegisters mipsEnv
    regsF = floatRegisters mipsEnv
    r3  = fi $ tv `mod` (1 `shift` 8 )                 -- least significant
    r2  = fi $ (tv `shift` (-8)) `mod` (1 `shift` 8)
    r1  = fi $ (tv `shift` (-8*2)) `mod` (1 `shift` 8)
    r0  = fi $ (tv `shift` (-8*3)) `mod` (1 `shift` 8)
    in do
    put mipsEnv { intRegisters = regsI,
                floatRegisters = regsF,
                memory = ((take ta mem) ++ [r0,r1,r2,r3] ++ (drop (ta+4) mem)) }