How to assign inconstant value to reg in Task , In Verilog? - initialization

I have faced this Error. Although I seek whole the net, I did not find good answer.
I want to assign a conditional value to a reg in a Task.
The Error is this :
Error: VCP2648 Control_Unit_Tasks.v : (60, 50): Reg initializer must be a constant: DR==10'b0000000000?1'b1:1'b0";
And My written code for a Task which arises this error is this:
task Registers_Inc_Generator(output PC_inc,DR_inc,AC_inc, input [7:0]D,T, input[5:0]B, input[9:0] AC,DR, input R,Z);
reg isDR_Zero=(DR==10'b0000000000)?1'b1:1'b0;
reg isAC_Zero=(AC==10'b0000000000)?1'b1:1'b0;
endtask
I will appreciate if anyone help me. Thanks.

The error message is quite self-explanatory. When you have
reg isDR_Zero=(DR==10'b0000000000)?1'b1:1'b0;
you are initialising a variable. You can only initialise a variable to a constant value. Instead you must declare the variables first and then assign to them:
task Registers_Inc_Generator(output PC_inc,DR_inc,AC_inc, input [7:0]D,T, input[5:0]B, input[9:0] AC,DR, input R,Z);
begin
reg isDR_Zero;
reg isAC_Zero;
isDR_Zero=(DR==10'b0000000000)?1'b1:1'b0;
isAC_Zero=(AC==10'b0000000000)?1'b1:1'b0;
end
endtask

Related

How can I access variables in nested structures the same way as unnested variables in Julia?

I am new to Julia, so I am sorry if this is an obvious or easy question. I tried googling it, but could not find a good solution.
In Julia, there is no inheritence. My solution to this is to have structures encapsulating structures. E.g.:
mutable struct A
Var1::Int64
end
mutable struct B
StructA::A
Var2::Int64
end
MyA = A(1)
MyB = B(MyA, 2)
Now, when I want to get Var2, I just do:
MyB.Var2
>2
To get Var1, I can do:
MyB.StructA.Var1
>1
Or I can do:
Var1(x::B) = x.StructA.Var1
Var1(MyB)
>1
But now for my question, can I also (re)define a function such that I can do this?:
MyB.Var1
>1
I tried just typing the access to Var1, hoping that the function I defined above would automatically be extended to this use. But I got the expected error:
MyB.Var1
ERROR: type B has no field Var1
I also tried defining the function myself:
x::B.Var1 = x.StructA.Var1
ERROR: type DataType has no field Var1
(x::B).Var1 = x.StructA.Var1
ERROR: UndefVarError: x not defined
These errors do not surprise me. But I do not know how to get what I want, if it is at all possible.
Thanks in advance!
Yes, this is possible by extending getproperty for your type:
function Base.getproperty(b::B, s::Symbol)
if s == :Var1
return b.StructA.Var1
else
return getfield(b, s)
end
end
Now you can just write:
julia> MyB.Var1
1
More info here: https://docs.julialang.org/en/v1/base/base/#Base.getproperty
There is also a corresponding setproperty! function for modifying fields.

PL/SQL wrong number or types of arguments in call to 'P'

I have a very simple situation in PL/SQL application.
I create an array like so:
TYPE myArrayType IS TABLE OF myList%ROWTYPE;
myArray myArrayType;
myList is a cursor with 63 rows. Later in my code I try to loop trough my newly created array like so:
htp.p('<h2>My data table</h2>');
htp.p('<table>');
for elem in 1 .. myArray.count loop
htp.p('<tr>');
htp.p('<td>');
htp.p(' Data= '||myArray(elem)||' '); // <-- ERROR
htp.p('</td>');
htp.p('</tr>');
end loop;
htp.p('</table>');
But I get an error 'wrong number or types of arguments', can someone please help a newbie?
In the line:
htp.p(' Data= '||myArray(elem)||' '); // <-- ERROR
You are trying to concatenate string with the record, therefore you are getting an error. To fix your problem you have to provide the column name existing in this record:
htp.p(' Data= '||myArray(elem).column_name||' ');

PLS-00103: Encountered the symbol “CREATE”

its showing error in 27 line create or replace function Buffalo
Declare
random_number number(4);
user_number number(4);
cow number(1);
buffaloes number(1):=0;
begin
random_number:=uniquetest(random_number);
/*random_number:=dbms_random.value(1000,9999);*/
dbms_output.put_line(random_number);
user_number:=&user_number;
while(user_number!=random_number)
loop
buffaloes:=Buffalo(user_number,random_number);
dbms_output.put_line('0'||'c'||buffaloes||'B');
buffaloes:=0;
user_number:=0;
user_number:=&user_number;
end loop;
end;
/*error in this line */
create or replace function Buffalo
(user_number in number,random_number in number)
return number
is
user_comparision number(1);
random_comparision number(1);
buffaloes number(1);
user_number1 number(4):=user_number;
random_number1 number(4):=random_number;
begin
while(user_number!=random_number)
loop
user_comparision:=user_number1 mod 10;
random_comparision:=random_number1 mod 10;
user_number1:=user_number1/10;
random_number1:=random_number1/10;
if(user_comparision = random_comparision)
then
buffaloes:=buffaloes+1;
end if;
end loop;
return buffaloes;
end;/
it is showing error in create statement. can anybody help me in solving this error.
Tell how to solve this create statement error.
it is showing error in create statement. can anybody help me in solving this error.
Tell how to solve this create statement error.
You should make 2 scripts of it. Currently you're starting off with a anonymous block, that is actually calling the function buffalo, while it hasn't been created yet.
Both the anonymous block and the function seem to be creating some infinite loop by the way,
So I'm not sure what you're trying to achieve here..
Without knowing the background of this problem it's impossible to give a solution.

Array of Dictionaries - Julia

I'm trying to make a constructor for a custom type in Julia:
type Cell
Base::Dict{String, String}
zLayers::Array{Dict{String, String},2}
X::Int
Y::Int
Cell() = new(Dict{String,String}(),[Dict{String, String}(),Dict{String, String}()],0,0)
end
try
gamestate = Cell()
catch err
print("connection ended with error $err\n")
end
Throws error:
connection ended with error MethodError(convert,(Array{Dict{String,String},2},[Dict{String,String}(),Dict{String,String}()]))
So how do we do proper initialization for Arrays of Dictionaries?
This question was double posted and answered on the mailiglist.
https://groups.google.com/forum/m/#!topic/julia-users/zE8Ri8rbfHQ
I think you’re confusing the 2 in an Array parameter set with the number of items, when it’s the number of dimensions. I’m pretty sure you’re creating a Vector, not a Matrix.

C# - Datetime convertion and GetDayOfYear usage fails

There's the code:
HebrewCalendar Heb = new HebrewCalendar();
DateTime tmp = new DateTime(1964,2,3);
MessageBox.Show(Heb.GetDayOfYear(tmp));
it's very basic and simple, but yet - i get an errors:
Error 1 The best overloaded method match for System.Windows.Forms.MessageBox.Show(string)' has some invalid arguments..
Error 2 Argument 1: cannot convert from 'int' to 'string'
what is the problem?
I'm not familiar with HebrewCalendar, but given the error message, I'd say that GetDayOfYear is returning an integer.
Try this:
MessageBox.Show(Heb.GetDayOfYear(tmp).ToString());
MessageBox.Show doesn't know how to deal with integers. If you convert it to a string first, it will show you the string representation.

Resources