'-nographic',
                '-s', '-S']
 
+def swap_order(x, nbytes):
+    x = x.to_bytes(nbytes, byteorder='little')
+    x = int.from_bytes(x, byteorder='big', signed=False)
+    return x
+
 
 class QemuController:
     def __init__(self, kernel, bigendian):
                                            stdout=subprocess.PIPE,
                                            stdin=subprocess.PIPE)
         self.gdb = GdbController(gdb_path='powerpc64-linux-gnu-gdb')
+        self.bigendian = bigendian
 
     def __enter__(self):
         return self
         for x in res:
             if(x["type"]=="result"):
                 assert 'register-values' in x['payload']
-                return int(x['payload']['register-values'][0]['value'], 0)
+                res = int(x['payload']['register-values'][0]['value'], 0)
+                return res
+                #return swap_order(res, 8)
         return None
 
     # TODO: use -data-list-register-names instead of hardcoding the values
 
 from soc.decoder.isa.all import ISA
 from soc.fu.test.common import TestCase
 from soc.simulator.test_sim import DecoderBase
-
+from soc.config.endian import bigendian
 
 
 class TrapSimTestCases(FHDLTestCase):
         lst = ["addi 1, 0, 0x5678",
                "twi  4, 1, 0x5677",
                ]
-        with Program(lst) as program:
+        with Program(lst, bigendian) as program:
             self.run_tst_program(program, [1])
 
     def test_1_twi_eq(self):
         lst = ["addi 1, 0, 0x5678",
                "twi  4, 1, 0x5678",
                ]
-        with Program(lst) as program:
+        with Program(lst, bigendian) as program:
             self.run_tst_program(program, [1])
 
     def run_tst_program(self, prog, initial_regs=None, initial_sprs=None,