check.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #include <stdio.h>
  2. #include <inttypes.h>
  3. #include <assert.h>
  4. #include "prcalc.h"
  5. int main (int argc, char** argv) {
  6. prc_context ctx;
  7. uint64_t op1=0, op2=0;
  8. prc_init_context(&ctx);
  9. // This should have zero flags
  10. op1 = 10;
  11. op2 = 10;
  12. prc_push(&ctx, op1);
  13. prc_push(&ctx, op2);
  14. prc_add_stack(&ctx);
  15. assert(ctx.registers.FLAGS == 0);
  16. 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);
  17. // This should have zero flags
  18. op1 = -1;
  19. op2 = 10;
  20. prc_push(&ctx, op1);
  21. prc_push(&ctx, op2);
  22. prc_add_stack(&ctx);
  23. assert(ctx.registers.FLAGS == 0);
  24. 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);
  25. //This should have negative flag
  26. op1 = -1;
  27. op2 = -10;
  28. prc_push(&ctx, op1);
  29. prc_push(&ctx, op2);
  30. prc_add_stack(&ctx);
  31. assert(ctx.registers.FLAGS == 2);
  32. 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);
  33. // This should be negative flag and unsigned flag
  34. op1 = 0b0111111111111111111111111111111111111111111111111111111111111111;
  35. op2 = 1;
  36. prc_push(&ctx, op1);
  37. prc_push(&ctx, op2);
  38. prc_add_stack(&ctx);
  39. assert(ctx.registers.FLAGS == 10);
  40. 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);
  41. // This should be a overflow flag and negative
  42. op1 = 1;
  43. op2 = 0b1111111111111111111111111111111111111111111111111111111111111111;
  44. prc_push(&ctx, op1);
  45. prc_push(&ctx, op2);
  46. prc_add_stack(&ctx);
  47. assert(ctx.registers.FLAGS == 6);
  48. 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);
  49. // This should have zero flags
  50. op1 = 4;
  51. op2 = 25;
  52. prc_push(&ctx, op1);
  53. prc_push(&ctx, op2);
  54. prc_mul_stack(&ctx);
  55. assert(ctx.registers.FLAGS == 0);
  56. 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);
  57. //prc_mul_stack(&ctx);
  58. //printf("RESULT: %ld \nFLAGS: %d\n", ctx.registers.A, ctx.registers.FLAGS);
  59. }