You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

28 lines
724 B

  1. #include "addition.h"
  2. #include <stdlib.h>
  3. void full_adder (num* sum, num* nextcarry, num number1, num number2, num carry) {
  4. sum[0] = (number1 % 2) ^ (number2 % 2) ^ (carry % 2);
  5. nextcarry[0] = ((number1 % 2) & (number2 % 2)) | ((number1 % 2) & (carry % 2)) | ((number2 % 2) & (carry % 2));
  6. }
  7. unsigned int addition(num number1, num number2) {
  8. unsigned int result = 0;
  9. num sum[1] = {0};
  10. num nextcarry[1] = {0};
  11. for (int i = 0; i < 8 * sizeof(num); i++)
  12. {
  13. full_adder(sum, nextcarry, number1, number2, nextcarry[0]);
  14. result ^= (sum[0] << i);
  15. number1 >>= 1;
  16. number2 >>= 1;
  17. }
  18. return result;
  19. }
  20. float addition_float(float a, float b) {
  21. return 0.0;
  22. }