Browse Source

Add comparison methods

Yann Weber 6 years ago
parent
commit
62a4306158
1 changed files with 44 additions and 2 deletions
  1. 44
    2
      gte/turmit.py

+ 44
- 2
gte/turmit.py View File

@@ -238,7 +238,49 @@ class Turmit(object):
238 238
         pass
239 239
     
240 240
     @RpnOp
241
-    def jmp(self, a):
241
+    def jmp(self, offset):
242 242
         ''' @brief Increments IP
243
+            @param offset int : jump offset symbols
243 244
         '''
244
-        self.__ip += a
245
+        self.__ip += offset
246
+
247
+    @RpnOp
248
+    def jz(self, a, offset):
249
+        ''' @brief Increments IP if a == 0
250
+            @param a int : operand
251
+            @param offset int : jump offset symbols
252
+        '''
253
+        if a == 0:
254
+            self.__ip += offset
255
+
256
+    @RpnOp
257
+    def jnz(self, a, offset):
258
+        ''' @brief Increments IP if a != 0
259
+            @param a int : operand
260
+            @param offset int : jump offset symbols
261
+        '''
262
+        if a != 0:
263
+            self.__ip += offset
264
+
265
+    @RpnOp
266
+    def jcmp(self, a, b, cnd, offset):
267
+        ''' @brief Increments IP if a == b
268
+
269
+            Condition type is encoded on an int : 
270
+            - 0b0000 : je
271
+            - 0b0001 : jne
272
+            - 0b0010 : jle
273
+            - 0b0011 : jl
274
+            - 0b0100 : jg
275
+            - 0b0101 : jge
276
+            - 0b0110 : jne
277
+            - 0b0111 : jmp
278
+
279
+            @param a int : operand
280
+            @param b int : operand
281
+            @param cnd int : condition type
282
+            @param offset int : jump offset symbols
283
+        '''
284
+        jmp = False
285
+        if cnd & 1 and a == b or cnd & 0b10 and a < b or cnd & 0b100 and a > b:
286
+            self.__ip += offset

Loading…
Cancel
Save