0% found this document useful (0 votes)
0 views10 pages

COA LAB Merged

The lab report details the addition, subtraction, and multiplication of unsigned integer binary numbers using various methods. It includes theoretical explanations, Verilog code implementations, test cases, and results for each operation. The report concludes that programmatic approaches simplify binary arithmetic operations and ensure accuracy.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views10 pages

COA LAB Merged

The lab report details the addition, subtraction, and multiplication of unsigned integer binary numbers using various methods. It includes theoretical explanations, Verilog code implementations, test cases, and results for each operation. The report concludes that programmatic approaches simplify binary arithmetic operations and ensure accuracy.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

TRIBHUVAN UNIVERSITY

INSTITUTE OF ENGINEERING
PURWANCHAL CAMPUS DHARAN
Department of Electronics and Computer Engineering

LAB REPORT ON COMPUTER ORGANIZATION AND ARCHITETCTURE

Submitted By: Submitted To:

Name : Sonu Kumar Gupta Er. Sujan Karki


Roll : PUR078BCT084
Year/Part : III/I
Addition of two unsigned integer binary number.
Theory:
Binary addition rules:
0+0=0
0+1=1
1+0=1
1 + 1 = 0 (with a carry of 1)
When adding binary numbers, if the sum exceeds 1, a carry is generated to the next higher bit
position. This is analogous to carrying over in decimal addition when the sum exceeds 9.

Program:
// design.sv
module UnsignedAdder(
input [4:0] A, // 5-bit input A
input [4:0] B, // 5-bit input B
output [4:0] Sum, // 5-bit output for the sum
output CarryOut // Output for the carry out
);
// Internal signals
reg [4:0] sum_temp; // Temporary sum to handle overflow
reg carry_temp; // Temporary carry
// Add A and B
always @(A,B) begin
{carry_temp, sum_temp} = A + B;
end
// Output signals
assign CarryOut = carry_temp; // Output the carry out
assign Sum = (carry_temp) ? {1'b1, sum_temp} : sum_temp; // Adjust sum based on carry
endmodule

// testbench.sv
module testbench;
// Inputs
reg [4:0] A;
reg [4:0] B;
// Outputs
wire [4:0] Sum;
wire CarryOut;
// Instantiate the UnsignedAdder module
UnsignedAdder dut (A,B,Sum,CarryOut);
// Stimulus generation
initial begin
$dumpfile("dump.vcd");
$dumpvars(1);
// Test case 1: A = 8, B = 7
A = 5'b01000;
B = 5'b00111;
#10; // Wait for 10 time units
// Display simulation results
$display("A = %b, B = %b, Sum = %b, CarryOut = %b", A, B, Sum, CarryOut);
// Test case 2: A = 7, B = 31
A = 5'b00111;
B = 5'b11111;
#10; // Wait for 10 time units
// Display simulation results
$display("A = %b, B = %b, Sum = %b, CarryOut = %b", A, B, Sum, CarryOut);
end
endmodule

Output:
# KERNEL: A = 01000, B = 00111, Sum = 01111, CarryOut = 0
# KERNEL: A = 00111, B = 11111, Sum = 00110, CarryOut = 1

Result & Conclusion:


Hence, the addition of two unsigned integer binary numbers was performed. The
programmatic approach simplifies the process, especially for larger binary numbers, and ensures
error-free computation.
TRIBHUVAN UNIVERSITY
INSTITUTE OF ENGINEERING
PURWANCHAL CAMPUS DHARAN
Department of Electronics and Computer Engineering

LAB REPORT ON COMPUTER ORGANIZATION AND ARCHITETCTURE

Submitted By: Submitted To:

Name : Sonu Kumar Gupta Er. Sujan Karki


Roll : PUR078BCT084
Year/Part : III/I
Subtraction of two unsigned integer binary number.
Theory:
Binary subtraction rules:
0–0=0
1–0=1
1–1=0
0 – 1 = 1 (with a borrow of 1 from the next higher bit)
When subtracting binary numbers, if the minuend (top number) bit is smaller than the subtrahend
(bottom number) bit, borrowing is required from the next higher bit position. This process is
analogous to borrowing in decimal subtraction

Program:
// design.sv
module BinarySubtractor4Bit(
input [3:0] A, // 4-bit input for the first binary number
input [3:0] B, // 4-bit input for the second binary number
output reg [3:0] diff, // 4-bit output for the difference
output reg borrow_out // Output for the borrow
);
always @* begin
// Initialize borrow_out to 0
borrow_out = 1'b0;
// Calculate the difference bit by bit, starting from the LSB
for (int i = 0; i < 4; i = i + 1) begin
// Calculate the difference of the current bits and the borrow
diff[i] = A[i] ^ B[i] ^ borrow_out;
// Update the borrow for the next bit subtraction
if (~A[i] & (B[i] | borrow_out))
borrow_out = 1'b1;
else
borrow_out = 1'b0;
end
end
endmodule
// testbench.sv
module testbench;
// Inputs
reg [3:0] A;
reg [3:0] B;
// Outputs
wire [3:0] diff;
wire borrow_out;
// Instantiate the UnsignedAdder module
BinarySubtractor4Bit dut (A,B,diff,borrow_out);
// Stimulus generation
initial begin
$dumpfile("dump.vcd");
$dumpvars(1);
// Test case 1: A = 6, B = 4
A = 4'b0110;
B = 4'b0100;
#10; // Wait for 10 time units
// Display simulation results
$display("A = %b, B = %b, diff = %b, borrow_out = %b", A, B, diff, borrow_out);
// Test case 2: A = 7, B = 15
A = 4'b0111;
B = 4'b1111;
#10; // Wait for 10 time units
// Display simulation results
$display("A = %b, B = %b, diff = %b, borrow_out = %b", A, B, diff, borrow_out);
end
endmodule

Output:

# KERNEL: A = 0101, B = 0011, diff = 0010, borrow_out = 0


# KERNEL: A = 0111, B = 1111, diff = 1000, borrow_out = 1
Result & Conclusion:
Hence, the subtraction of two unsigned integer binary number was done. The subtraction of
binary numbers, while more complex than addition due to the need for borrowing, can be accurately
performed manually or programmatically. The borrow mechanism in binary subtraction ensures that
the operations conform to binary number system rules. The programmatic approach automates the
process, ensuring consistency and accuracy, especially for larger binary numbers.
TRIBHUVAN UNIVERSITY
INSTITUTE OF ENGINEERING
PURWANCHAL CAMPUS DHARAN
Department of Electronics and Computer Engineering

LAB REPORT ON COMPUTER ORGANIZATION AND ARCHITETCTURE

Submitted By: Submitted To:

Name : Sonu Kumar Gupta Er. Sujan Karki


Roll : PUR078BCT084
Year/Part : III/I
Multiplication of two unsigned Integer Binary numbers by Partial-Product Method.
Theory:
Binary multiplication rules:
0*0=0
0*1=0
1*0=0
1*1=1
In the partial-product method, each bit of the multiplier is multiplied by the entire multiplicand, and
these partial products are shifted according to the bit's position and then summed to obtain the final
product.

Program:
// design.sv
module PartialProductMultiplication(
input [3:0] A,
input [3:0] B,
output reg [7:0] Product
);
reg [7:0] partial_products[3:0];
integer i;
always @(A, B) begin
// Initialize the product and partial products to 0
Product = 8'b0;
for (i = 0; i < 4; i = i + 1)
partial_products[i] = 8'b0;
// Generate partial products
for (i = 0; i < 4; i = i + 1) begin
if (B[i])
partial_products[i] = A << i;
end
// Sum the partial products
for (i = 0; i < 4; i = i + 1)
Product = Product + partial_products[i];
end
endmodule
// testbench.sv
module testbench;
reg [3:0] A;
reg [3:0] B;
wire [7:0] Product;
// Instantiate the multiplication module
PartialProductMultiplication dut (A, B, Product);
initial begin
$dumpfile("dump.vcd");
$dumpvars(1);
// Test case 1
A = 4'b1010; // 10 in decimal
B = 4'b1100; // 12 in decimal
#10;
// Test case 2
A = 4'b1001; // 9 in decimal
B = 4'b0101; // 5 in decimal
#10;
// Test case 3
A = 4'b0110; // 6 in decimal
B = 4'b0011; // 3 in decimal
#10;
end
always @* begin
$display("A: %b, B: %b, Product: %b", A, B, Product);
end
endmodule
Output:
# KERNEL: A: 1010, B: 1100, Product: xxxxxxxx
# KERNEL: A: 1010, B: 1100, Product: 01111000
# KERNEL: A: 1001, B: 0101, Product: 01111000
# KERNEL: A: 1001, B: 0101, Product: 00101101
# KERNEL: A: 0110, B: 0011, Product: 00101101
# KERNEL: A: 0110, B: 0011, Product: 00010010

Result & Conclusion:


Hence, the multiplication of two unsigned integer binary numbers by Partial-Product Method
was done. The multiplication of binary numbers using the partial-product method involves generating
partial products for each bit of the multiplier and summing them. This method is straightforward and
mirrors the manual multiplication process.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy