PROGRAM IN MATLAB FOR SUBTRACTION OF TWO UNSIGNED INTEGER BINARY NUMBER (4BITS NUMBERS)
function lab3_coa
a=input('enter a:');
b=input('enter b:');
c=0;
temp=a;
for i=4:-1:1
if(b(1,i)==1)
b(1,i)=0;
else
b(1,i)=1;
end
end
a=[0 0 0 1];
for i=4:-1:1
sum=xor(xor(a(1,i),b(1,i)),c);
carry=or(and(a(1,i),b(1,i)),and(xor(a(1,i),b(1,i)),c));
c=carry;
result(1,i)=sum;
end
a=temp;
b=result;
c=0;
for i=4:-1:1
sum=xor(xor(a(1,i),b(1,i)),c);
carry=or(and(a(1,i),b(1,i)),and(xor(a(1,i),b(1,i)),c));
c=carry;
result(1,i)=sum;
end
if(c==0)
fprintf('The number is negative.');
for i=4:-1:1
if(result(1,i)==1)
result(1,i)=0;
else
result(1,i)=1;
end
end
a=[0 0 0 1];
for i=4:-1:1
sum=xor(xor(a(1,i),result(1,i)),c);
carry=or(and(a(1,i),result(1,i)),and(xor(a(1,i),result(1,i)),c));
c=carry;
result(1,i)=sum;
end
end
disp(result);
disp(c);
end
Saturday, January 20, 2018
Home »
MATLAB Programs - COA
» Computer Organisation & Architecture
0 comments:
Post a Comment