Lab Report
Lab Report
Project
HW/SW Final Project
Name
[1] Lê Công Đức 19119041
Student [2] Trần Hoàng Anh Tú ID 22119034
[3] Lương Anh Tài 22119030
Class Supervisor Assoc. Prof. Phan Van Ca
Do you verify that the code included with this report is your's original work
(YES/NO)? ________
A. DESIGN PROJECT
SC_MODULE(ALU4bit) {
sc_in<sc_uint<4>> A, B; // 4-bit inputs
sc_in<sc_uint<4>> op_code; // 4-bit operation selector
sc_out<sc_uint<4>> result; // 4-bit result
sc_out<bool> carry_borrow; // Carry or Borrow
void process() {
sc_uint<4> a = A.read();
sc_uint<4> b = B.read();
sc_uint<4> op = op_code.read();
sc_uint<4> res = 0;
bool cb = 0;
switch (op) {
case 0x0: // ADD
res = a + b;
cb = (a + b) > 15;
break;
case 0x1: // SUB
res = a - b;
cb = a < b; // borrow
break;
case 0x2: // INC A
res = a + 1;
cb = (a + 1) > 15;
break;
case 0x3: // DEC A
res = a - 1;
cb = (a == 0);
break;
case 0x4: // AND
res = a & b;
cb = false;
break;
case 0x5: // OR
res = a | b;
cb = false;
break;
case 0x6: // NAND
res = ~(a & b);
cb = false;
break;
case 0x7: // XOR
res = a ^ b;
cb = false;
break;
default:
res = 0;
cb = false;
}
result.write(res);
carry_borrow.write(cb);
}
SC_CTOR(ALU4bit) {
SC_METHOD(process);
sensitive << A << B << op_code;
}
};
// full_subtractor.cpp
#include <systemc.h>
SC_MODULE(FullSubtractor) {
sc_in<bool> A, B, Bin; // Inputs: A, B, Borrow-in
sc_out<bool> Diff, Bout; // Outputs: Difference, Borrow-out
void process_subtract() {
bool a = A.read();
bool b = B.read();
bool bin = Bin.read();
Diff.write(a ^ b ^ bin);
Bout.write((!a & b) | (!a & bin) | (b & bin));
}
SC_CTOR(FullSubtractor) {
SC_METHOD(process_subtract);
sensitive << A << B << Bin;
}
};
module ALU_4bit (
input [3:0] A,
input [3:0] B,
input [3:0] opcode,
output reg [3:0] result,
output reg carry_out
);
endmodule
while (!done_s.read()) {
wait(1, SC_NS);
}
nnDIGITmult multiplier("Hardware_Multiplier");
multiplier.enable(enable_s);
multiplier.in_data_1(dataI1);
multiplier.in_data_2(dataI2);
multiplier.out_data_low(dataO1);
multiplier.out_data_high(dataO2);
multiplier.done(done_s);
sc_start(2000000, SC_NS);
return 0;
}
This project built on previous work involving SystemC module creation by introducing
concurrency and real-time HW/SW communication. We leveraged earlier modules such as
the GCD logic and expanded them with handshake protocols and FSMs for hardware
integration. The knowledge from ALU and multiplexer designs was essential for structuring
hardware logic efficiently