瀏覽代碼

libprcalc: added acert to check_flags

Douglas A 4 年之前
父節點
當前提交
419257e888
共有 2 個文件被更改,包括 19 次插入6 次删除
  1. 17 5
      libprcalc/check.c
  2. 2 1
      libprcalc/prcalc.h

+ 17 - 5
libprcalc/check.c

@@ -1,6 +1,8 @@
 #include <stdio.h>
-#include "prcalc.h"
 #include <inttypes.h>
+#include <assert.h>
+
+#include "prcalc.h"
 
 
 int main (int argc, char** argv) {
@@ -11,49 +13,59 @@ int main (int argc, char** argv) {
     prc_init_context(&ctx);
    
 
+    // This should have zero flags
     op1 = 10;
     op2 = 10;
     prc_push(&ctx, op1);
     prc_push(&ctx, op2);
     prc_add_stack(&ctx);
+    assert(ctx.registers.FLAGS == 0);
     printf("ADD(%20." PRIi64 ", %20." PRIi64 ")\tuint64_t: %20." PRIu64 "\tint64_t: %20." PRIi64 "\tHex: %16.lx\tFlags: %d\n", op1, op2,  ctx.registers.A, ctx.registers.A, ctx.registers.A, ctx.registers.FLAGS);
 
+    // This should have zero flags
     op1 = -1;
     op2 = 10;
     prc_push(&ctx, op1);
     prc_push(&ctx, op2);
     prc_add_stack(&ctx);
+    assert(ctx.registers.FLAGS == 0);
     printf("ADD(%20." PRIi64 ", %20." PRIi64 ")\tuint64_t: %20." PRIu64 "\tint64_t: %20." PRIi64 "\tHex: %16.lx\tFlags: %d\n", op1, op2,  ctx.registers.A, ctx.registers.A, ctx.registers.A, ctx.registers.FLAGS);
 
+    //This should have negative flag
     op1 = -1;
     op2 = -10;
     prc_push(&ctx, op1);
     prc_push(&ctx, op2);
     prc_add_stack(&ctx);
+    assert(ctx.registers.FLAGS == 2);
     printf("ADD(%20." PRIi64 ", %20." PRIi64 ")\tuint64_t: %20." PRIu64 "\tint64_t: %20." PRIi64 "\tHex: %16.lx\tFlags: %d\n", op1, op2,  ctx.registers.A, ctx.registers.A, ctx.registers.A, ctx.registers.FLAGS);
 
-
+    // This should be negative flag and unsigned flag
     op1 = 0b0111111111111111111111111111111111111111111111111111111111111111;
     op2 = 1;
     prc_push(&ctx, op1);
     prc_push(&ctx, op2);
     prc_add_stack(&ctx);
+    assert(ctx.registers.FLAGS == 10);
     printf("ADD(%20." PRIi64 ", %20." PRIi64 ")\tuint64_t: %20." PRIu64 "\tint64_t: %20." PRIi64 "\tHex: %16.lx\tFlags: %d\n", op1, op2,  ctx.registers.A, ctx.registers.A, ctx.registers.A, ctx.registers.FLAGS);
 
-    op1 = 2;
+
+    // This should be a overflow flag and negative
+    op1 = 1;
     op2 = 0b1111111111111111111111111111111111111111111111111111111111111111; 
     prc_push(&ctx, op1);
     prc_push(&ctx, op2);
     prc_add_stack(&ctx);
+    assert(ctx.registers.FLAGS == 6);
     printf("ADD(%20." PRIu64 ", %20." PRIu64 ")\tuint64_t: %20." PRIu64 "\tint64_t: %20." PRIi64 "\tHex: %16.lx\tFlags: %d\n", op1, op2,  ctx.registers.A, ctx.registers.A, ctx.registers.A, ctx.registers.FLAGS);
 
-
-
+    // This should have zero flags
     op1 = 4;
     op2 = 25;
     prc_push(&ctx, op1);
     prc_push(&ctx, op2);
     prc_mul_stack(&ctx);
+    assert(ctx.registers.FLAGS == 0);
     printf("ADD(%20." PRIi64 ", %20." PRIi64 ")\tuint64_t: %20." PRIu64 "\tint64_t: %20." PRIi64 "\tHex: %16.lx\tFlags: %d\n", op1, op2,  ctx.registers.A, ctx.registers.A, ctx.registers.A, ctx.registers.FLAGS);
 
 

+ 2 - 1
libprcalc/prcalc.h

@@ -9,6 +9,7 @@
 #define CARRY 1
 #define NEGATIVE 2
 #define OVERFLOW 4
+#define UNSIGNED 8
 
 typedef enum BOOL {FALSE, TRUE} _PRC_BOOL;
 
@@ -20,7 +21,7 @@ typedef enum BOOL {FALSE, TRUE} _PRC_BOOL;
  *  1 -> Carry bit
  *  2 -> Negative
  *  4 -> Overflow
- *  8 -> 
+ *  8 -> Unsigned
  *  16 -> 
  *  32 -> 
  *  64 ->