THIS CODE WORKS CAN SOMEONE MODIFY IT TO LOOK A LITTLE DIFFE

THIS CODE WORKS, CAN SOMEONE MODIFY IT TO LOOK A LITTLE DIFFERENT BUT STILL DO THE SAME THING.
ADD A LOT OF COMMENTS!!!!
The code is used to add two binary numbers
The circuit has an xor gate, or gate & and gate .
First three leds are A B and Cin and next two are Cout and Sum
Can someone please add comments to the code and explain what each part does, and re write the code to be more efficient!! If their is another way to write the code. Please do so but make it very similar. Needs to be in \"C\" #include Kmsp430.h int main(void) WDTCTL WDTPW WDTHOLD; Stop watchdog timer P1DIR I 0x07 Set P1.0 to output direction for (R) volatile unsigned int i,j; for (i eix8 itt. P10UT i; Toggle P1.0 using exclusive-OR for return

Solution


c program for halfadder and fulladder

#include<stdio.h>

typedef char bit;
bit bit_carry = 0;
bit halfadder( bit A, bit B ){
bit_carry = A & B;
return A ^ B;
}
bit fulladder( bit A, bit B ){
bit xor = A ^ B;
bit result = bit_carry ^ xor;
bit_carry = (bit_carry & xor) | (A & B);
return result;
}

void fillNumber( int number, bit *array ){
int i;
for( i = 0; i < 32; ++ i ){
array[i] = ( number >> i ) & 1;
}
}

int main(){
bit number1[32] = {0}, number2[32] = {0};
int A = 64620926, B = 1531529858;
fillNumber( A, number1 );
fillNumber( B, number2 );

int x = 0;
bit tmp_result = halfadder( number1[0], number2[0] );
putchar( tmp_result ? \'1\' : \'0\' );
x = tmp_result;
int i;
for( i = 1; i < 32; ++i ){
tmp = fulladder( number11[i], number22[i] );
x += tmp_result << i;
putchar( tmp_result ? \'1\' : \'0\' );
}
putchar( bit_carry ? \'1\' : \'0\' );
printf(\"\ %d\ \ %d + %d = %d\", x, A, B, A+B);
return 0;
}

THIS CODE WORKS, CAN SOMEONE MODIFY IT TO LOOK A LITTLE DIFFERENT BUT STILL DO THE SAME THING. ADD A LOT OF COMMENTS!!!! The code is used to add two binary numb

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site