diff --git a/asm/ffi.py b/asm/ffi.py index 3442171..54a47dc 100644 --- a/asm/ffi.py +++ b/asm/ffi.py @@ -89,7 +89,7 @@ class Environment: return creole.from_2c(self.cenv.reg[reg]) else: return self.cenv.reg[reg] - def getstk(self, stk): + def getstk(self, stk, signed=False): """ Get the value at the stack position. :param reg: Register number. @@ -98,7 +98,16 @@ class Environment: """ if stk >= self.cenv.stklen or stk < 0: raise StackOverflowError(r) - return creole.from_2c(self.cenv.stk[stk]) + if signed: + return creole.from_2c(self.cenv.stk[stk]) + else: + return self.cenv.stk[stk] + + def pop(self): + if stk == 0: + return None + stk = stk - 1 + return self.cenv.stk[stk] def __init__(self, prog=None, reglen=32, lablen=32, stklen=4096, prglen=4096): cenv = CEnv() diff --git a/asm/test.py b/asm/test.py index 19778b5..d50b555 100644 --- a/asm/test.py +++ b/asm/test.py @@ -434,5 +434,22 @@ class ProgramTest(unittest.TestCase): self.range_test(0x7FFFF00, 0x8000000, sgn=True) self.range_test(-100, 0, sgn=True) +class SCEnv(ffi.Environment): + def syscall(self, s): + self.s = s.value + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + +class ProgramTest(unittest.TestCase): + def range_test(self, st, en, sgn=False): + for i in range(st, en): + p = Program() + p.parse_asm_line(f"sys {i}") + ex = SCEnv(p()) + self.assertEqual(ex(), ffi.RunRet.STOP) + self.assertEqual(ex.s, i) + def test_syscall_imm(self): + self.range_test(0, 1000) + if __name__ == "__main__": unittest.main()