SlideShare a Scribd company logo
1 of 15
COMPUTER ORGANIZATION & ARCHITECTURE LAB
1
LAB@1
Full Marks: 25 Pass Marks: 10
Marks Distribution
Mark Distribution Criteria Mark Remark
Attendance 8
Lab report 8
Viva 8
Discipline 1
Total 25
Lab Report Format
 Title
 Background Theory
 MATLAB tools used in your lab program
 Algorithm&Flowchart
 Code
 Output : Screen shots/handwritten output
 Discussion & Conclusion
Integer representation (Fixed point representation):
 Only have 0 & 1 to represent everything
 Positive numbers stored in binary; e.g. 41=00101001
 No minus sign and No period
 Sign-Magnitude
 Left most bit (MSB) is sign bit
 0 means positive and 1 means negative e.g. +18 = 00010010 and -18 = 10010010
 Problems: Need to consider both sign and magnitude in arithmetic&Two
representations of zero (+0 and -0)
 Two’s compliment
 2’s compliment representation uses the most significant bit (MSB) as sign bit
making it easy to rest whether the integer is negative or positive. It differs from
the use of sign magnitude representation in the way the other bits are interpreted.
For negation take the Boolean complement of each bit of corresponding positive
number and then add one to the resulting bit pattern viewed as unsigned integer.
COMPUTER ORGANIZATION & ARCHITECTURE LAB
2
 +3 = 00000011 and -3 = 11111101
 Benefits:
 One representation of zero
 Arithmetic works easily
 Negating is fairly easy
 3 = 00000011
 Boolean complement gives 11111100 then add 1 to LSB11111101
Addition and Subtraction
 Normal binary addition
 Monitor sign bit for overflow
 Take twos compliment of subtrahend and add to minuend
 i.e. a - b = a + (-b) ,So we only need addition and complement circuits
For example
The 2’s complement of 0111 is 1001 and is obtained by leaving first 1 unchanged, and then
replacing 1’s by 0’s and 0’s by 1’s in the other three most significant bits. Let us see an
example of subtraction using two binary numbers X = 10(1010) and Y = 9 (1001) and
perform X-Y and Y-X.
X = 1010
2’s complement of Y = +0111
-----------
Sum = 10001
Discard end carry 24 = -10000
----------
Answer: X-Y = 0001
Y = 1001
2’s complement of X = +0110
-----------
Sum = 1111
There is no end carry
Answer is negative 0001 = 2’s compliment of 1111 and for addition of 2’s complement use
same algorithm.
COMPUTER ORGANIZATION & ARCHITECTURE LAB
3
Hardware for Addition and Subtraction
Figure: Hardware implementation of Addition/Subtraction
To implement the two arithmetic operations with hardware, it is first necessary that the two
numbers to be stored in registers. Let A and B be two registers that hold the magnitude of the
numbers and As and Bs be two flip-flops that hold the corresponding signs. The result of the
operation may be transferred to a third register.
The data path and hardware elements needed to accomplish addition and subtraction is shown in
Fig. 5.1. The center element is binary adder, which is presented two numbers for addition and
produces a sum and an overflow indication. The binary adder treats from two registers A and B.
the result may be stored in one of these registers or in the third register. The overflow indication
is stored in a 1-bit overflow flag. For subtraction, the subtrahend (B register) is passed through a
2’s complement unit so that its 2’s complement is presented to the adder (a-b=a + (-b)).
COMPUTER ORGANIZATION & ARCHITECTURE LAB
4
Logical operation:
The fundamental logic gate family
The seven fundamental logic gates are:
1. NOT (Inverter)
2. AND
3. NAND
4. OR
5. NOR
6. XOR
7. XNOR
COMPUTER ORGANIZATION & ARCHITECTURE LAB
5
Main program to add two unsigned binary number [4 bit binary adder]
%******* Main Program Code*******%
display('Enter First Binary Sequence')
for i=1:4
a(i)=input('');
end
display('Enter Second Binary Sequence')
for i=1:4
b(i)=input('');
end
carry=0;
for i=4:-1:1
c(i)=xors(xors(a(i),b(i)),carry);
carry=ors(ands(a(i),b(i)),ands(xors(a(i),b(i)),carry));
end
%*******************************************
fprintf('%d',a)
fprintf('n')
fprintf('%d',b)
fprintf('+n')
display('=====================')
fprintf('%d%d',carry,c)
fprintf('n')
Function for AND operation
function [res] = ands(a,b)
if(a==1) && (b==1)
res=1;
else
res=0;
end
end
Function for XOR operation
function [res]= xors(a,b)
if (a~=b)
res=1;
else
res=0;
end
end
Function for OR operation
function [res] = ors(a,b)
if (a==0) && (b==0)
res=0;
else
res=1;
end
end
COMPUTER ORGANIZATION & ARCHITECTURE LAB
6
Lab@2
%%***** Matlab code for subtraction *******%%
display('Enter First Number')
for i=1:4
a(i)=input('');
end
display ('Enter Second Number')
for i=1:4
b(i)=input('');
end
%%2's complement of Second Sequence
for i=1:4
b(i)=xor(1,b(i));
end
c=1;% for 2's complement we add 1 so initialize carry as 1
for i=4:-1:1
[s (i) c] = adder ( a(i) , b(i) , c);
end
display('result')
%% Carry decide the result is in negative or positive. ifCayy is 0 then
%% result is negative else result is positive
if (c==0)
for (i=1:4)
s(i) = xor(1,s(i));
end
car=1;
for (i=4:-1:1)
[s(i) , car] = adder(s(i),0,car);
end
%display('Negative')
fprintf('-')
COMPUTER ORGANIZATION & ARCHITECTURE LAB
7
fprintf('%d',s)
else
%display('Positive')
fprintf('+')
fprintf('%d',s)
end
% Plotting input and output
subplot(3,1,1)
stem(a,'R');
xlabel('First sequence');
subplot(3,1,2);
stem(b,'G');
xlabel('Second Sequence');
subplot(3,1,3);
stem(s,'B');
xlabel('Result(a-b)');
Function for Addition Operation
function [res,car] = adder(a,b,c)
res= xor(xor(a,b),c);
car= or(and(a,b),and(xor(a,b),c));
end
COMPUTER ORGANIZATION & ARCHITECTURE LAB
8
Lab@3
Multiplication Algorithm
 Complex
 Work out partial product for each digit
 Take care with place value (column)
 Add partial products
Example:
1011 Multiplicand (11 decimal)
X 1101 Multiplier (13 decimal)
1011 Partial products
0000 Note: if multiplier bit is 1 copy multiplicand (place value)
1011 otherwise zero
1011
10001111 Product (143 Dec)
Note: need double length result
Hardware Implementation:
COMPUTER ORGANIZATION & ARCHITECTURE LAB
9
The multiplier and multiplicand bits are loaded into two registers Q and M. A third register A is
initially set to zero. C is the 1 bit register which holds the carry bit resulting from addition. Now,
the control logic reads the bits of the multiplier one at a time. If Q0 is 1, the multiplicand is added
to the register A and is stored back in register A with C bit used for carry. Then all the bits of
CAQ are shifted to the right 1 bit so that C bit goes to An-1, A0 goes to Qn-1 and Q0 is lost. If Q0 is
0, no addition is performed just do the shift. The process is repeated for each bit of the original
multiplier. The resulting 2n bit product is contained in the QA register.
Flowchart for unsigned binary multiplication
COMPUTER ORGANIZATION & ARCHITECTURE LAB
10
%% Matlab code for Multiplication of two unsigned 4-bit binary number
clearall;
closeall;
R=[0 0 0 0 0 0 0 0];
display('Enter First Number');
for i=5:8
A(i)=input('');
end
display ('Enter Second Number');
for i=5:8
B(i)=input('');
end
display('***==============================***');
fprintf('Multiplicant=');
fprintf('%d',A);
fprintf('n');
fprintf('Multiplier=');
fprintf('%d',B);
fprintf('n');
fprintf('***************************');
subplot(3,1,1);
stem(A,'G');
xlabel('Multiplicant');
if(B(8)==1)
R=A;% Assign the given number First partial product
end
for i=7:-1:5
if(B(i)==1)
c=0;
for j=8:-1:1
[A(j) c]=adds(A(j),A(j),c);
COMPUTER ORGANIZATION & ARCHITECTURE LAB
11
end
c=0;
for j=8:-1:1
[ R(j) c]=adds(R(j),A(j),c);% shifting left
end
else
c=0;
for j=8:-1:1
[A(j) c]=adds(A(j),A(j),c);
end
end
end
%% Result Plotting
fprintf('n');
fprintf('Multiplication result=');
fprintf('%d',R);
fprintf('n');
display('***==============================***');
subplot(3,1,2);
stem(B,'R');
xlabel('Multiplier');
subplot(3,1,3);
stem(R);
xlabel('Result after multiplication');
COMPUTER ORGANIZATION & ARCHITECTURE LAB
12
Lab@4
Division of Unsigned Binary Integers
Hardware implementation of division algorithm
Restoring Division:
This method is called restoring division because the partial remainder is restored by adding the
divisor to the negative difference. Here division process requires controlled subtract-restore
operations. Whether the next operation is a subtraction or restoration, is controlled by the
result of the current operation.
Shift left
Divisor
Add/Subtract
An An-1 .....………. An
0 Mn-1 ……..…... Mn
Qn-1 ……..…… … Q0
N+1 Bit
Adder
Control
unit
COMPUTER ORGANIZATION & ARCHITECTURE LAB
13
Flowchart of Restoring Division algorithm
Algorithm
Step1: Initialize A 0, dividend (Q) & divisor (M) registers and counter 0
Step2: Shift left A, Q on binary position.
Step3: If MSB of A is 1, set Q (0)  0 and add M back to A (restore A), else set Q (0)  1
Step4: counter counter + 1; if couner ≠ n-1 where n is the number of bits in the dividend,
repeat process from step2 else stop the process. Finally remainder will be in A and
Quotient will be in Q.
COMPUTER ORGANIZATION & ARCHITECTURE LAB
14
%% Matlab Code for restoring Division algorithm [two 4-bit binary number %%
A = [ 0 0 0 0 ];
B = [0 0 0 0];
disp('Enter Dividend:')
for i=1:4
Q(i)=input('');
end
disp('Enter Divisor:')
for j=1:4
B(j)=input('');
end
%% Display Input Data
display('Dividend:');
Q
display('Divisor:');
B
%% code of 2's complement of Divisor
c=1;
for i=4:-1:1
[nB(i) c]=adds(xor(B(i),1),0,c);
end
%% Main code start
for cnt=1:4
% Shift operation (left Shift A, Q)
[A Q]=shifts(A,Q);
C=0;
% Subtraction operation (A=A-B)
for i=4:-1:1
[A(i) C]=adds(A(i),nB(i),C);
end
% Check MSB of A
COMPUTER ORGANIZATION & ARCHITECTURE LAB
15
if(A(1)==0)
Q(4)=1; % Set LSB of Q
else
Q(4)=0; % Set LSB of Q
c=0;
% Addition Operation (A=A+B)
for i=4:-1:1
[A(i) C] = adds(A(i),B(i),C);
end
end
end
%% Result Display
disp('Quotient: ')
Q
disp('Remainder: ')
A
%% Plotting Result
subplot(2,2,1);
stem(Q, 'Y');
xlabel('Dividend');
subplot(2,2,2);
stem(B,'B');
xlabel('Divisor');
subplot(2,2,3);
stem(Q,'R');
xlabel('Quotient');
subplot(2,2,4);
stem(A,'G');
xlabel('Remainder');

More Related Content

What's hot

Error Correction And Hamming Code Ibrar
Error Correction And Hamming Code IbrarError Correction And Hamming Code Ibrar
Error Correction And Hamming Code Ibraribrar562
 
Quine Mc Clusky (Tabular) method
Quine Mc Clusky (Tabular) methodQuine Mc Clusky (Tabular) method
Quine Mc Clusky (Tabular) methodSyed Saeed
 
binary arithmetic rules
binary arithmetic rulesbinary arithmetic rules
binary arithmetic rulesstudent
 
Presentation on Karnaugh Map
Presentation  on Karnaugh MapPresentation  on Karnaugh Map
Presentation on Karnaugh MapKawsar Ahmed
 
CPU Register Organization.ppt
CPU Register Organization.pptCPU Register Organization.ppt
CPU Register Organization.pptprathamgunj
 
Flip flops, counters & registers
Flip flops, counters & registersFlip flops, counters & registers
Flip flops, counters & registersDharit Unadkat
 
Combinational Logic Circuit
Combinational Logic CircuitCombinational Logic Circuit
Combinational Logic CircuitGargiKhanna1
 
Logical and shift micro operations
Logical and shift micro operationsLogical and shift micro operations
Logical and shift micro operationsSanjeev Patel
 
Jump&Loop instruction
Jump&Loop instructionJump&Loop instruction
Jump&Loop instructionjosnapv
 
Booth’s algorithm.(a014& a015)
Booth’s algorithm.(a014& a015)Booth’s algorithm.(a014& a015)
Booth’s algorithm.(a014& a015)Piyush Rochwani
 
Modified booths algorithm part 1
Modified booths algorithm part 1Modified booths algorithm part 1
Modified booths algorithm part 1babuece
 
Addition and subtraction with signed magnitude data (mano
Addition and subtraction with signed magnitude data (manoAddition and subtraction with signed magnitude data (mano
Addition and subtraction with signed magnitude data (manocs19club
 
Latches and flip flop
Latches and flip flopLatches and flip flop
Latches and flip flopShuaib Hotak
 

What's hot (20)

Error Correction And Hamming Code Ibrar
Error Correction And Hamming Code IbrarError Correction And Hamming Code Ibrar
Error Correction And Hamming Code Ibrar
 
Quine Mc Clusky (Tabular) method
Quine Mc Clusky (Tabular) methodQuine Mc Clusky (Tabular) method
Quine Mc Clusky (Tabular) method
 
Microprogrammed Control Unit
Microprogrammed Control UnitMicroprogrammed Control Unit
Microprogrammed Control Unit
 
binary arithmetic rules
binary arithmetic rulesbinary arithmetic rules
binary arithmetic rules
 
Presentation on Karnaugh Map
Presentation  on Karnaugh MapPresentation  on Karnaugh Map
Presentation on Karnaugh Map
 
Multiplexers & Demultiplexers
Multiplexers & DemultiplexersMultiplexers & Demultiplexers
Multiplexers & Demultiplexers
 
CPU Register Organization.ppt
CPU Register Organization.pptCPU Register Organization.ppt
CPU Register Organization.ppt
 
Input-Buffering
Input-BufferingInput-Buffering
Input-Buffering
 
K map
K mapK map
K map
 
Flip flops, counters & registers
Flip flops, counters & registersFlip flops, counters & registers
Flip flops, counters & registers
 
Combinational Logic Circuit
Combinational Logic CircuitCombinational Logic Circuit
Combinational Logic Circuit
 
Logical and shift micro operations
Logical and shift micro operationsLogical and shift micro operations
Logical and shift micro operations
 
Jump&Loop instruction
Jump&Loop instructionJump&Loop instruction
Jump&Loop instruction
 
K map.
K map.K map.
K map.
 
Booth’s algorithm.(a014& a015)
Booth’s algorithm.(a014& a015)Booth’s algorithm.(a014& a015)
Booth’s algorithm.(a014& a015)
 
Modified booths algorithm part 1
Modified booths algorithm part 1Modified booths algorithm part 1
Modified booths algorithm part 1
 
Unit 4-booth algorithm
Unit 4-booth algorithmUnit 4-booth algorithm
Unit 4-booth algorithm
 
Adder
Adder Adder
Adder
 
Addition and subtraction with signed magnitude data (mano
Addition and subtraction with signed magnitude data (manoAddition and subtraction with signed magnitude data (mano
Addition and subtraction with signed magnitude data (mano
 
Latches and flip flop
Latches and flip flopLatches and flip flop
Latches and flip flop
 

Similar to Binary Arithmetic Lab Report

Comp Arithmetic Basic.ppt
Comp Arithmetic Basic.pptComp Arithmetic Basic.ppt
Comp Arithmetic Basic.pptskatiarrahaman
 
100_2_digitalSystem_Chap1 (2).ppt
100_2_digitalSystem_Chap1 (2).ppt100_2_digitalSystem_Chap1 (2).ppt
100_2_digitalSystem_Chap1 (2).pptnamraashraf56
 
ArithmeticCircuits.Ivy Nile vs. Rhea Ripley
ArithmeticCircuits.Ivy Nile vs. Rhea RipleyArithmeticCircuits.Ivy Nile vs. Rhea Ripley
ArithmeticCircuits.Ivy Nile vs. Rhea RipleyRudraBhai3
 
COMPUTER ORGANIZATION NOTES Unit 6
COMPUTER ORGANIZATION NOTES Unit 6COMPUTER ORGANIZATION NOTES Unit 6
COMPUTER ORGANIZATION NOTES Unit 6Dr.MAYA NAYAK
 
07_arithmeticcircuits digital electronics.pptx
07_arithmeticcircuits digital electronics.pptx07_arithmeticcircuits digital electronics.pptx
07_arithmeticcircuits digital electronics.pptxElisée Ndjabu
 
Module 4_Digital Electronics till complements.pdf
Module 4_Digital Electronics till complements.pdfModule 4_Digital Electronics till complements.pdf
Module 4_Digital Electronics till complements.pdfmanjunath V Gudur
 
Chapter 07 Digital Alrithmetic and Arithmetic Circuits
Chapter 07 Digital Alrithmetic and Arithmetic CircuitsChapter 07 Digital Alrithmetic and Arithmetic Circuits
Chapter 07 Digital Alrithmetic and Arithmetic CircuitsSSE_AndyLi
 
digital systems and information
digital systems and informationdigital systems and information
digital systems and informationKamran Zafar
 
Arithmetic Unit Addition Subtraction Multiplication and Division
Arithmetic Unit Addition Subtraction Multiplication and DivisionArithmetic Unit Addition Subtraction Multiplication and Division
Arithmetic Unit Addition Subtraction Multiplication and DivisionRNShukla7
 
Unit-8-Computer-Arithmetic.pdf
Unit-8-Computer-Arithmetic.pdfUnit-8-Computer-Arithmetic.pdf
Unit-8-Computer-Arithmetic.pdfGafryMahmoud
 
2 Computer Arithmetic_hhbyhbjhhjjjjjb41.pptx
2 Computer Arithmetic_hhbyhbjhhjjjjjb41.pptx2 Computer Arithmetic_hhbyhbjhhjjjjjb41.pptx
2 Computer Arithmetic_hhbyhbjhhjjjjjb41.pptxMtikuTadesse
 
IRJET-Design and Implementation of LNS based Approximate Multiplier using Mit...
IRJET-Design and Implementation of LNS based Approximate Multiplier using Mit...IRJET-Design and Implementation of LNS based Approximate Multiplier using Mit...
IRJET-Design and Implementation of LNS based Approximate Multiplier using Mit...IRJET Journal
 
Computer Architecture refers to those attributes of a system that have a dire...
Computer Architecture refers to those attributes of a system that have a dire...Computer Architecture refers to those attributes of a system that have a dire...
Computer Architecture refers to those attributes of a system that have a dire...mayurjagdale4
 

Similar to Binary Arithmetic Lab Report (20)

Comp Arithmetic Basic.ppt
Comp Arithmetic Basic.pptComp Arithmetic Basic.ppt
Comp Arithmetic Basic.ppt
 
Computer arithmetic
Computer arithmeticComputer arithmetic
Computer arithmetic
 
100_2_digitalSystem_Chap1 (2).ppt
100_2_digitalSystem_Chap1 (2).ppt100_2_digitalSystem_Chap1 (2).ppt
100_2_digitalSystem_Chap1 (2).ppt
 
ArithmeticCircuits.Ivy Nile vs. Rhea Ripley
ArithmeticCircuits.Ivy Nile vs. Rhea RipleyArithmeticCircuits.Ivy Nile vs. Rhea Ripley
ArithmeticCircuits.Ivy Nile vs. Rhea Ripley
 
COMPUTER ORGANIZATION NOTES Unit 6
COMPUTER ORGANIZATION NOTES Unit 6COMPUTER ORGANIZATION NOTES Unit 6
COMPUTER ORGANIZATION NOTES Unit 6
 
07_arithmeticcircuits digital electronics.pptx
07_arithmeticcircuits digital electronics.pptx07_arithmeticcircuits digital electronics.pptx
07_arithmeticcircuits digital electronics.pptx
 
Module 4_Digital Electronics till complements.pdf
Module 4_Digital Electronics till complements.pdfModule 4_Digital Electronics till complements.pdf
Module 4_Digital Electronics till complements.pdf
 
Chapter 07 Digital Alrithmetic and Arithmetic Circuits
Chapter 07 Digital Alrithmetic and Arithmetic CircuitsChapter 07 Digital Alrithmetic and Arithmetic Circuits
Chapter 07 Digital Alrithmetic and Arithmetic Circuits
 
digital systems and information
digital systems and informationdigital systems and information
digital systems and information
 
Lec20
Lec20Lec20
Lec20
 
Arithmetic Unit Addition Subtraction Multiplication and Division
Arithmetic Unit Addition Subtraction Multiplication and DivisionArithmetic Unit Addition Subtraction Multiplication and Division
Arithmetic Unit Addition Subtraction Multiplication and Division
 
Unit-8-Computer-Arithmetic.pdf
Unit-8-Computer-Arithmetic.pdfUnit-8-Computer-Arithmetic.pdf
Unit-8-Computer-Arithmetic.pdf
 
2 Computer Arithmetic_hhbyhbjhhjjjjjb41.pptx
2 Computer Arithmetic_hhbyhbjhhjjjjjb41.pptx2 Computer Arithmetic_hhbyhbjhhjjjjjb41.pptx
2 Computer Arithmetic_hhbyhbjhhjjjjjb41.pptx
 
computer arithmatic
computer arithmaticcomputer arithmatic
computer arithmatic
 
CA UNIT II.pptx
CA UNIT II.pptxCA UNIT II.pptx
CA UNIT II.pptx
 
IRJET-Design and Implementation of LNS based Approximate Multiplier using Mit...
IRJET-Design and Implementation of LNS based Approximate Multiplier using Mit...IRJET-Design and Implementation of LNS based Approximate Multiplier using Mit...
IRJET-Design and Implementation of LNS based Approximate Multiplier using Mit...
 
COA(Unit_3.pptx)
COA(Unit_3.pptx)COA(Unit_3.pptx)
COA(Unit_3.pptx)
 
Alu1
Alu1Alu1
Alu1
 
09 Arithmetic
09  Arithmetic09  Arithmetic
09 Arithmetic
 
Computer Architecture refers to those attributes of a system that have a dire...
Computer Architecture refers to those attributes of a system that have a dire...Computer Architecture refers to those attributes of a system that have a dire...
Computer Architecture refers to those attributes of a system that have a dire...
 

More from Shankar Gangaju (20)

Tutorial no. 8
Tutorial no. 8Tutorial no. 8
Tutorial no. 8
 
Tutorial no. 7
Tutorial no. 7Tutorial no. 7
Tutorial no. 7
 
Tutorial no. 6
Tutorial no. 6Tutorial no. 6
Tutorial no. 6
 
Tutorial no. 3(1)
Tutorial no. 3(1)Tutorial no. 3(1)
Tutorial no. 3(1)
 
Tutorial no. 5
Tutorial no. 5Tutorial no. 5
Tutorial no. 5
 
Tutorial no. 4
Tutorial no. 4Tutorial no. 4
Tutorial no. 4
 
Tutorial no. 2
Tutorial no. 2Tutorial no. 2
Tutorial no. 2
 
Tutorial no. 1.doc
Tutorial no. 1.docTutorial no. 1.doc
Tutorial no. 1.doc
 
What is a computer
What is a computerWhat is a computer
What is a computer
 
Pointer
PointerPointer
Pointer
 
Array
ArrayArray
Array
 
9.structure & union
9.structure & union9.structure & union
9.structure & union
 
6.array
6.array6.array
6.array
 
5.program structure
5.program structure5.program structure
5.program structure
 
4. function
4. function4. function
4. function
 
3. control statement
3. control statement3. control statement
3. control statement
 
2. operator
2. operator2. operator
2. operator
 
1. introduction to computer
1. introduction to computer1. introduction to computer
1. introduction to computer
 
Ads lab
Ads labAds lab
Ads lab
 
Electromagnetic formula
Electromagnetic formulaElectromagnetic formula
Electromagnetic formula
 

Recently uploaded

Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfMahmoud M. Sallam
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxDr.Ibrahim Hassaan
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxJiesonDelaCerna
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentInMediaRes1
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaVirag Sontakke
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Blooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxBlooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxUnboundStockton
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementmkooblal
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupJonathanParaisoCruz
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxEyham Joco
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...jaredbarbolino94
 
MICROBIOLOGY biochemical test detailed.pptx
MICROBIOLOGY biochemical test detailed.pptxMICROBIOLOGY biochemical test detailed.pptx
MICROBIOLOGY biochemical test detailed.pptxabhijeetpadhi001
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfMr Bounab Samir
 

Recently uploaded (20)

Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdf
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptx
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptx
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media Component
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of India
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Blooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxBlooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docx
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of management
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized Group
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptx
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...
 
MICROBIOLOGY biochemical test detailed.pptx
MICROBIOLOGY biochemical test detailed.pptxMICROBIOLOGY biochemical test detailed.pptx
MICROBIOLOGY biochemical test detailed.pptx
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
 

Binary Arithmetic Lab Report

  • 1. COMPUTER ORGANIZATION & ARCHITECTURE LAB 1 LAB@1 Full Marks: 25 Pass Marks: 10 Marks Distribution Mark Distribution Criteria Mark Remark Attendance 8 Lab report 8 Viva 8 Discipline 1 Total 25 Lab Report Format  Title  Background Theory  MATLAB tools used in your lab program  Algorithm&Flowchart  Code  Output : Screen shots/handwritten output  Discussion & Conclusion Integer representation (Fixed point representation):  Only have 0 & 1 to represent everything  Positive numbers stored in binary; e.g. 41=00101001  No minus sign and No period  Sign-Magnitude  Left most bit (MSB) is sign bit  0 means positive and 1 means negative e.g. +18 = 00010010 and -18 = 10010010  Problems: Need to consider both sign and magnitude in arithmetic&Two representations of zero (+0 and -0)  Two’s compliment  2’s compliment representation uses the most significant bit (MSB) as sign bit making it easy to rest whether the integer is negative or positive. It differs from the use of sign magnitude representation in the way the other bits are interpreted. For negation take the Boolean complement of each bit of corresponding positive number and then add one to the resulting bit pattern viewed as unsigned integer.
  • 2. COMPUTER ORGANIZATION & ARCHITECTURE LAB 2  +3 = 00000011 and -3 = 11111101  Benefits:  One representation of zero  Arithmetic works easily  Negating is fairly easy  3 = 00000011  Boolean complement gives 11111100 then add 1 to LSB11111101 Addition and Subtraction  Normal binary addition  Monitor sign bit for overflow  Take twos compliment of subtrahend and add to minuend  i.e. a - b = a + (-b) ,So we only need addition and complement circuits For example The 2’s complement of 0111 is 1001 and is obtained by leaving first 1 unchanged, and then replacing 1’s by 0’s and 0’s by 1’s in the other three most significant bits. Let us see an example of subtraction using two binary numbers X = 10(1010) and Y = 9 (1001) and perform X-Y and Y-X. X = 1010 2’s complement of Y = +0111 ----------- Sum = 10001 Discard end carry 24 = -10000 ---------- Answer: X-Y = 0001 Y = 1001 2’s complement of X = +0110 ----------- Sum = 1111 There is no end carry Answer is negative 0001 = 2’s compliment of 1111 and for addition of 2’s complement use same algorithm.
  • 3. COMPUTER ORGANIZATION & ARCHITECTURE LAB 3 Hardware for Addition and Subtraction Figure: Hardware implementation of Addition/Subtraction To implement the two arithmetic operations with hardware, it is first necessary that the two numbers to be stored in registers. Let A and B be two registers that hold the magnitude of the numbers and As and Bs be two flip-flops that hold the corresponding signs. The result of the operation may be transferred to a third register. The data path and hardware elements needed to accomplish addition and subtraction is shown in Fig. 5.1. The center element is binary adder, which is presented two numbers for addition and produces a sum and an overflow indication. The binary adder treats from two registers A and B. the result may be stored in one of these registers or in the third register. The overflow indication is stored in a 1-bit overflow flag. For subtraction, the subtrahend (B register) is passed through a 2’s complement unit so that its 2’s complement is presented to the adder (a-b=a + (-b)).
  • 4. COMPUTER ORGANIZATION & ARCHITECTURE LAB 4 Logical operation: The fundamental logic gate family The seven fundamental logic gates are: 1. NOT (Inverter) 2. AND 3. NAND 4. OR 5. NOR 6. XOR 7. XNOR
  • 5. COMPUTER ORGANIZATION & ARCHITECTURE LAB 5 Main program to add two unsigned binary number [4 bit binary adder] %******* Main Program Code*******% display('Enter First Binary Sequence') for i=1:4 a(i)=input(''); end display('Enter Second Binary Sequence') for i=1:4 b(i)=input(''); end carry=0; for i=4:-1:1 c(i)=xors(xors(a(i),b(i)),carry); carry=ors(ands(a(i),b(i)),ands(xors(a(i),b(i)),carry)); end %******************************************* fprintf('%d',a) fprintf('n') fprintf('%d',b) fprintf('+n') display('=====================') fprintf('%d%d',carry,c) fprintf('n') Function for AND operation function [res] = ands(a,b) if(a==1) && (b==1) res=1; else res=0; end end Function for XOR operation function [res]= xors(a,b) if (a~=b) res=1; else res=0; end end Function for OR operation function [res] = ors(a,b) if (a==0) && (b==0) res=0; else res=1; end end
  • 6. COMPUTER ORGANIZATION & ARCHITECTURE LAB 6 Lab@2 %%***** Matlab code for subtraction *******%% display('Enter First Number') for i=1:4 a(i)=input(''); end display ('Enter Second Number') for i=1:4 b(i)=input(''); end %%2's complement of Second Sequence for i=1:4 b(i)=xor(1,b(i)); end c=1;% for 2's complement we add 1 so initialize carry as 1 for i=4:-1:1 [s (i) c] = adder ( a(i) , b(i) , c); end display('result') %% Carry decide the result is in negative or positive. ifCayy is 0 then %% result is negative else result is positive if (c==0) for (i=1:4) s(i) = xor(1,s(i)); end car=1; for (i=4:-1:1) [s(i) , car] = adder(s(i),0,car); end %display('Negative') fprintf('-')
  • 7. COMPUTER ORGANIZATION & ARCHITECTURE LAB 7 fprintf('%d',s) else %display('Positive') fprintf('+') fprintf('%d',s) end % Plotting input and output subplot(3,1,1) stem(a,'R'); xlabel('First sequence'); subplot(3,1,2); stem(b,'G'); xlabel('Second Sequence'); subplot(3,1,3); stem(s,'B'); xlabel('Result(a-b)'); Function for Addition Operation function [res,car] = adder(a,b,c) res= xor(xor(a,b),c); car= or(and(a,b),and(xor(a,b),c)); end
  • 8. COMPUTER ORGANIZATION & ARCHITECTURE LAB 8 Lab@3 Multiplication Algorithm  Complex  Work out partial product for each digit  Take care with place value (column)  Add partial products Example: 1011 Multiplicand (11 decimal) X 1101 Multiplier (13 decimal) 1011 Partial products 0000 Note: if multiplier bit is 1 copy multiplicand (place value) 1011 otherwise zero 1011 10001111 Product (143 Dec) Note: need double length result Hardware Implementation:
  • 9. COMPUTER ORGANIZATION & ARCHITECTURE LAB 9 The multiplier and multiplicand bits are loaded into two registers Q and M. A third register A is initially set to zero. C is the 1 bit register which holds the carry bit resulting from addition. Now, the control logic reads the bits of the multiplier one at a time. If Q0 is 1, the multiplicand is added to the register A and is stored back in register A with C bit used for carry. Then all the bits of CAQ are shifted to the right 1 bit so that C bit goes to An-1, A0 goes to Qn-1 and Q0 is lost. If Q0 is 0, no addition is performed just do the shift. The process is repeated for each bit of the original multiplier. The resulting 2n bit product is contained in the QA register. Flowchart for unsigned binary multiplication
  • 10. COMPUTER ORGANIZATION & ARCHITECTURE LAB 10 %% Matlab code for Multiplication of two unsigned 4-bit binary number clearall; closeall; R=[0 0 0 0 0 0 0 0]; display('Enter First Number'); for i=5:8 A(i)=input(''); end display ('Enter Second Number'); for i=5:8 B(i)=input(''); end display('***==============================***'); fprintf('Multiplicant='); fprintf('%d',A); fprintf('n'); fprintf('Multiplier='); fprintf('%d',B); fprintf('n'); fprintf('***************************'); subplot(3,1,1); stem(A,'G'); xlabel('Multiplicant'); if(B(8)==1) R=A;% Assign the given number First partial product end for i=7:-1:5 if(B(i)==1) c=0; for j=8:-1:1 [A(j) c]=adds(A(j),A(j),c);
  • 11. COMPUTER ORGANIZATION & ARCHITECTURE LAB 11 end c=0; for j=8:-1:1 [ R(j) c]=adds(R(j),A(j),c);% shifting left end else c=0; for j=8:-1:1 [A(j) c]=adds(A(j),A(j),c); end end end %% Result Plotting fprintf('n'); fprintf('Multiplication result='); fprintf('%d',R); fprintf('n'); display('***==============================***'); subplot(3,1,2); stem(B,'R'); xlabel('Multiplier'); subplot(3,1,3); stem(R); xlabel('Result after multiplication');
  • 12. COMPUTER ORGANIZATION & ARCHITECTURE LAB 12 Lab@4 Division of Unsigned Binary Integers Hardware implementation of division algorithm Restoring Division: This method is called restoring division because the partial remainder is restored by adding the divisor to the negative difference. Here division process requires controlled subtract-restore operations. Whether the next operation is a subtraction or restoration, is controlled by the result of the current operation. Shift left Divisor Add/Subtract An An-1 .....………. An 0 Mn-1 ……..…... Mn Qn-1 ……..…… … Q0 N+1 Bit Adder Control unit
  • 13. COMPUTER ORGANIZATION & ARCHITECTURE LAB 13 Flowchart of Restoring Division algorithm Algorithm Step1: Initialize A 0, dividend (Q) & divisor (M) registers and counter 0 Step2: Shift left A, Q on binary position. Step3: If MSB of A is 1, set Q (0)  0 and add M back to A (restore A), else set Q (0)  1 Step4: counter counter + 1; if couner ≠ n-1 where n is the number of bits in the dividend, repeat process from step2 else stop the process. Finally remainder will be in A and Quotient will be in Q.
  • 14. COMPUTER ORGANIZATION & ARCHITECTURE LAB 14 %% Matlab Code for restoring Division algorithm [two 4-bit binary number %% A = [ 0 0 0 0 ]; B = [0 0 0 0]; disp('Enter Dividend:') for i=1:4 Q(i)=input(''); end disp('Enter Divisor:') for j=1:4 B(j)=input(''); end %% Display Input Data display('Dividend:'); Q display('Divisor:'); B %% code of 2's complement of Divisor c=1; for i=4:-1:1 [nB(i) c]=adds(xor(B(i),1),0,c); end %% Main code start for cnt=1:4 % Shift operation (left Shift A, Q) [A Q]=shifts(A,Q); C=0; % Subtraction operation (A=A-B) for i=4:-1:1 [A(i) C]=adds(A(i),nB(i),C); end % Check MSB of A
  • 15. COMPUTER ORGANIZATION & ARCHITECTURE LAB 15 if(A(1)==0) Q(4)=1; % Set LSB of Q else Q(4)=0; % Set LSB of Q c=0; % Addition Operation (A=A+B) for i=4:-1:1 [A(i) C] = adds(A(i),B(i),C); end end end %% Result Display disp('Quotient: ') Q disp('Remainder: ') A %% Plotting Result subplot(2,2,1); stem(Q, 'Y'); xlabel('Dividend'); subplot(2,2,2); stem(B,'B'); xlabel('Divisor'); subplot(2,2,3); stem(Q,'R'); xlabel('Quotient'); subplot(2,2,4); stem(A,'G'); xlabel('Remainder');