Advertisement
Guest User

Untitled

a guest
Nov 21st, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.62 KB | None | 0 0
  1. /*
  2.  * test_alu.c
  3.  * Testing file for the ALU module
  4.  * Nikita Rao (nrao01) & Margaret Gorguissian (mgorgu01)
  5.  * November 18, 2017
  6.  */
  7.  
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10. #include <stdint.h>
  11. #include "alu.h"
  12.  
  13. void   test_addition();
  14. void   test_multiplication();
  15. void   test_division();
  16. void   test_nand();
  17. void test_alu();
  18.  
  19.  
  20. int main()
  21. {
  22.         //test_addition();
  23.         //test_multiplication();
  24.         //test_division();
  25.         //test_nand();
  26.         test_alu();
  27. }
  28.  
  29. /*void test_addition()
  30. {      
  31.         word sum = add(0, 1);
  32.         fprintf(stderr, "Adding 0 and 1: %u\n", sum);
  33.  
  34.         sum = add(1203, 1203);
  35.         fprintf(stderr, "Adding 1203 and 1203: %u\n", sum);
  36.  
  37.         sum = add(555, 666);
  38.         fprintf(stderr, "Adding 555 and 666: %u\n", sum);
  39.  
  40.         sum = add(0, 0);
  41.         fprintf(stderr, "Adding 0 and 0: %u\n", sum);
  42.        
  43.         sum = add(4294967294, 1);
  44.         fprintf(stderr, "Adding 4294967294 and 1: %u\n", sum);
  45.  
  46.         sum = add(4294967295, 1);
  47.         fprintf(stderr, "Adding 4294967295 and 1: %u\n", sum);
  48. }
  49.  
  50. void test_multiplication()
  51. {
  52.         word product = multiply(0, 1);
  53.         fprintf(stderr, "Multiplying 0 and 1: %u\n", product);
  54.  
  55.         product = multiply(1073741823, 2);
  56.         fprintf(stderr, "Multiplying 1073741823 and 2: %u\n", product);
  57.  
  58.         product = multiply(2.5, 2);
  59.         fprintf(stderr, "Multiplying 2.5 and 2: %u\n", product);
  60. }
  61.  
  62. void test_division()
  63. {
  64.         word quotient = divide (1, 1);
  65.         fprintf(stderr, "Dividing 1 by 1: %u \n", quotient);
  66.        
  67.         quotient = divide (5, 2);
  68.         fprintf(stderr, "Dividing 5 by 2: %u \n", quotient);
  69.  
  70.         quotient = divide (4294967295, 4);
  71.         fprintf(stderr, "Dividing 4294967295 by 4: %u \n", quotient);      
  72.  
  73.         quotient = divide (4294967295, -1);
  74.         fprintf(stderr, "Dividing 4294967295 by -1: %u \n", quotient);  
  75. }
  76.  
  77. void test_nand()
  78. {
  79.         word result = nand (0, 0);
  80.         fprintf(stderr, "nanding 0 and 0: %u \n", result);
  81.  
  82.  
  83.         result = nand (4294967295, -1);
  84.         fprintf(stderr, "nanding 4294967295 and -1: %u \n", result);
  85.  
  86. }*/
  87.  
  88. void test_alu()
  89. {
  90.         word result = perform_arithmetic(0, 1, 3);
  91.         fprintf(stderr, "Adding 0 and 1: %u\n", result);
  92.  
  93.         result = perform_arithmetic(1, 1, 4);
  94.         fprintf(stderr, "Multiplying 0 and 1: %u\n", result);
  95.        
  96.         result = perform_arithmetic(0, 0, 6);
  97.         fprintf(stderr, "Nanding 0 and 0: %u\n", result);
  98.  
  99.  
  100.         fprintf(stderr, "Attempting to divide by 0:\n" );
  101.         result = perform_arithmetic(0, 0, 5);
  102.  
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement