Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

System Verilog sortEight.sv Write a module sortEight, which accepts eight signed

ID: 3664366 • Letter: S

Question

System Verilog

sortEight.sv Write a module sortEight, which accepts eight signed values and returns eight signed values sorted from least to greatest. You should submit one le for this problem called “sortEight.sv”. Any additional modules should be included in the le. You should not change the interface provided below. (Hint: Start by constructing a sortTwo module and then drawing a block diagram for a parallel bubble sort).


// NAME POSTING ID

module sortEight (

input logic signed [ 1 5 : 0 ] A[ 7 : 0 ] ,

output logic signed [ 1 5 : 0 ] B[ 7 : 0 ] ) ;

// B[0] should contain the least ,

// and B[7] should contain the greatest
// Your code here

endmodule

Explanation / Answer


module in verilog is used for describing hardware, it can contain, always, intial and assign statments. To have clear sepration between testbench and design, SystemVerilog introduces program, which contains full enviroment for testbench.

A Program serves following purpose.

  
As such it is better use clocking for driving or sampling signals from outside to avoid race. A program is similar to

module, so it can contain ports, interfaces, final and initial statments.
  
Note : Program block can not contain always block.
One more important limitation of program block is. A module (design) can not call task/function inside a program block.

But a program can call task/function inside module (design).


Below is simple program example.
  
//+++++++++++++++++++++++++++++++++++++++++++++++++
// Simple Program with ports
//+++++++++++++++++++++++++++++++++++++++++++++++++
program simple(input wire clk,output logic reset,
enable, input logic [3:0] count);
//=================================================
// Initial block inside program block
//=================================================
initial begin
$monitor("@%0dns count = %0d",$time,count);
reset = 1;
enable = 0;
#20 reset = 0;
@ (posedge clk);
enable = 1;
repeat (5) @ (posedge clk);
enable = 0;
// Call task in module
simple_program.do_it();
end
//=================================================
// Task inside a module
//=================================================
task do_it();
$display("%m I am inside program");
endtask

endprogram
//=================================================
// Module which instanciates program block
//=================================================
module simple_program();
logic clk = 0;
always #1 clk ++;
logic [3:0] count;
wire reset,enable;
//=================================================
// Simple up counter
//=================================================
always @ (posedge clk)
if (reset) count <= 0;
else if (enable) count ++;
//=================================================
// Program is connected like a module
//=================================================
simple prg_simple(clk,reset,enable,count);
//=================================================
// Task inside a module
//=================================================
task do_it();
$display("%m I am inside module");
endtask
//=================================================
// Below code is illegal
//=================================================
//initial begin
// prg_simple.do_it();
//end

endmodule


Simulation : Program
@0ns count = x
@1ns count = 0
@23ns count = 1
@25ns count = 2
@27ns count = 3
@29ns count = 4
simple_program.do_it I am inside module
@31ns count = 5

Below is the code used for sorting:

module automatic test;
  
initial run();
  
function void run();

// Associative array of people's ages
int age[string];
age["bob"] = 32;
age["timmy"] = 4;
age["tyrian"] = 31;
  
begin
// Create an aray of people's names
string sorted_age[] = new [age.size()];
int index = 0;
foreach (age[i]) begin
sorted_age[index++] = i;
end

// Sort the array
sorted_age.sort() with (age[item]);
  
// Display sorted ages
$display("People sorted by age:");
foreach (sorted_age[k]) begin
$display("%s:%0d", sorted_age[k], age[sorted_age[k]]);
end
  
end

endfunction
  
endmodule

Output:

# run -all
# People sorted by age:
# timmy:4
# tyrian:31
# bob:32
# exit
Done