Posts

Showing posts from September, 2023

Check for PALINDROME of a String using SV

Image
 CODE: module tb; string s1 = "madam"; string s2; initial begin s2 = {<<8{s1}}; //Storing each character as 8-bits using Streaming Op. if(s1 == s2) $display("\n %s is a Palindrome \n", s1); else $display("\n %s is NOT a Palindrome \n", s1); end endmodule SAMPLE OUTPUT: With Different String match: module tb;   string s1 = "jolly";   string s2;   initial     begin       s2 = {<<8{s1}}; //Storing each character as 8-bits       $display("\nReversal of gn. string is: %s",s2);       if(s1 == s2)          $display("%s is a Palindrome \n", s1);       else          $display("(Given String)%s != %s(Reversed String)",s1,s2);       $display("Therefore, %s is NOT a Palindrome \n", s1);     end endmodule SAMPLE OUTPUT: You can buy me a coffee! https://www.buymeacoffee.com/ch...

Constraint to generate 100 phone numbers, where the first three digits should be '982'

Image
  CODE:   class phone_number; rand int num[]; constraint ph_num_size {num.size() == 10;} constraint ph_num {foreach(num[i]) { (num[i]>= 0) && (num[i]<10); if(i == 0) num[i] == 9; if(i == 1) num[i] == 8; if(i == 2) num[i] == 2; } } function void display(); $write("Mobile No. is: \""); foreach(num[i]) begin $write("%0p",num[i]); end $write("\""); $write("\n"); endfunction endclass module jk; phone_number ph; initial begin ph = new(); repeat(100) begin ph.randomize(); ph.display(); //$display("size is: %0d",ph.num.size()); end end endmodule           SAMPLE OUTPUT: