Possible to build a 32bit adder from 32 1-bit adders? - module

I am supposed to complete the module below, by creating 32 assignment statements
doesn't seem to be the right way of doing this. I know that i have to carry the cout up,
but when create and test a yAdder using a client module, I get incorrect about like 1 + 1 = 4 billion. lol. I know what it should do, I just don't know how to do it in verilog.
module yAdder(z,cout,a,b,cin);
output [31:0] z;
output cout;
input[31:0] a, b;
input cin;
wire[31:0] in,out;
yAdder1 mine[31:0](z,out,a,b,in);
assign in[0] = cin;
assign in[1] = out[0];
assign in[2] = out[0];
assign in[3] = out[0];
assign in[4] = out[0];
assign in[5] = out[0];
assign in[6] = out[0];
assign in[7] = out[0];
assign in[8] = out[0];
assign in[9] = out[0];
assign in[10] = out[0];
assign in[11] = out[0];
assign in[12] = out[0];
assign in[13] = out[0];
assign in[14] = out[0];
assign in[15] = out[0];
assign in[16] = out[0];
assign in[17] = out[0];
assign in[18] = out[0];
assign in[19] = out[0];
assign in[20] = out[0];
assign in[21] = out[0];
assign in[22] = out[0];
assign in[23] = out[0];
assign in[24] = out[0];
assign in[25] = out[0];
assign in[26] = out[0];
assign in[27] = out[0];
assign in[28] = out[0];
assign in[29] = out[0];
assign in[30] = out[0];
assign in[31] = out[0];
assign cout = out[0];
endmodule
and the 1 bit adder module.
module yAdder1(z,cout,a,b,cin);
output z, cout;
input a, b, cin;
xor left_xor(tmp,a,b);
xor right_xor(z,cin,tmp);
and left_and(outL,a,b);
and right_and(outR,tmp,cin);
or my_or(cout,outR,outL);
endmodule

Assigning out[0] to all in wires isn't probably the best idea. What you're looking for is probably something like this:
assign {cout,in} = {out,cin};

For this pre-lab, you're supposed imagine the 32-bit adder just like how we did our 4-bit adder in the last lab, and connect the carry-in/carry-out wires like this:
assign in[0] = cin;
assign in[1] = out[0];
assign in[2] = out[1];
assign in[3] = out[2];
assign in[4] = out[3];
assign in[5] = out[4];
assign in[6] = out[5];
assign in[7] = out[6];
assign in[8] = out[7];
assign in[9] = out[8];
assign in[10] = out[9];
assign in[11] = out[10];
assign in[12] = out[11];
assign in[13] = out[12];
assign in[14] = out[13];
assign in[15] = out[14];
assign in[16] = out[15];
assign in[17] = out[16];
assign in[18] = out[17];
assign in[19] = out[18];
assign in[20] = out[19];
assign in[21] = out[20];
assign in[22] = out[21];
assign in[23] = out[22];
assign in[24] = out[23];
assign in[25] = out[24];
assign in[26] = out[25];
assign in[27] = out[26];
assign in[28] = out[27];
assign in[29] = out[28];
assign in[30] = out[29];
assign in[31] = out[30];
assign cout = out[31];

Related

Julia DifferentialEquations.jl all variable output

I have the following example:
using DifferentialEquations
function test1(du,u,p,t)
a,b,c = p
d=a^0.1*(t+1)
e=u[1]/a
f=u[2]/d
du[1] = a*u[1]
du[2] = d*u[2]
du[3] = b*u[2] - c*u[3]
end
p = (2,0.75,0.8)
u0 = [1.0;1.0;1.0]
tspan = (0.0,3.0)
prob = ODEProblem(test1,u0,tspan,p)
sol = solve(prob,saveat=0.3)
The sol objects contain state outputs but, I need efficiently other variables ("d","e","f") as well.
The closest I can get is:
function test2(du,u,p,t)
global i
global Out_values
global sampletimes
a,b,c = p
d=a^0.1*(t+1)
e=u[1]/a
f=u[2]/d
if t in sampletimes
Out_values[1,i] = d
Out_values[2,i] = e
Out_values[3,i] = f
i=i+1
end
du[1] = a*u[1]
du[2] = d*u[2]
du[3] = b*u[2] - c*u[3]
end
sampletimes = tspan[1]:0.3:tspan[2]
Out_values = Array{Float64}(undef, 3, 2*11)
i=1
prob = ODEProblem(test2,u0,tspan,p)
sol = solve(prob,saveat=0.3,tstops=sampletimes)
However, this solution is not ideal because:
it duplicates saveat and I get two sets of slightly different outputs (not sure why), and
it can't expand if I decide not to use saveat and I want to output all solutions, i.e. sol = solve(prob).
Any help is appreciated.

nameError: name 'pivots' is not defined

Could you help me to solve the following problem,please ?
I did write a module in python . For the next module I need the following variables or values:
lastprice and lastpivotprice
What definition or script change is necessary, that this 2 variables are global variables)?
Actually if i try to call lastpivotprice outside the module i get the following error message:
nameError: name 'pivots' is not defined
Module Code: checkpivots.py
try:
df['High'].plot(label='high')
pivots =[]
dates = []
counter = 0
lastPivot = 0
Range = [0,0,0,0,0,0,0,0,0,0]
daterange = [0,0,0,0,0,0,0,0,0,0]
for i in df.index:
currentMax = max(Range , default=0)
value=round(df["High"][i],2)
Range=Range[1:9]
Range.append(value)
daterange=daterange[1:9]
daterange.append(i)
if currentMax == max(Range , default=0):
counter+=1
else:
counter = 0
if counter == 5:
lastPivot=currentMax
dateloc =Range.index(lastPivot)
lastDate = daterange[dateloc]
pivots.append(lastPivot)
dates.append(lastDate)
except Exception:
print("-")
lastpivotprice = pivots[-1]
lastprice=df.iloc[-1]['Close'] #read value in the last row in col 'close'
lastprice2 = df['Close'].values[-2] #read value in the last row minus2 in col 'close'
#print (lastprice)
# print (lastpivotprice)
# print (lastprice2)
If you want to take your variables in every module as globals, you have to set them as global variables. For example see this code below:
c = 0 # global variable
def add():
global c
c = c + 2 # increment by 2
print("Inside add():", c)
add()
print("In main:", c)
If you delete global from c, the c remains 0 in MAIN.

How to assign notification to work order through BAPI?

I would like to assign a notification to a work order. The following does not work:
* Fill method structure
ls_methods-refnumber = 1.
ls_methods-method = 'SAVE'.
APPEND ls_methods TO lt_methods.
ls_methods-refnumber = 1.
ls_methods-objecttype = 'OBJECTLIST'.
ls_methods-method = 'CHANGE'.
ls_methods-objectkey = '000480000020'.
APPEND ls_methods TO lt_methods.
ls_methods-refnumber = 1.
ls_methods-objecttype = 'HEADER'.
ls_methods-method = 'CHANGE'.
ls_methods-objectkey = '000480000020'.
APPEND ls_methods TO lt_methods.
* Fill header structure
ls_header-orderid = '000480000020'.
ls_header-notif_no = '100000356980'.
APPEND ls_header TO lt_header.
* Fill header up structure
ls_header_up-orderid = '000480000020'.
ls_header_up-notif_no = '100000356980' .
APPEND ls_header_up TO lt_header_up.
* Fill object list structure
ls_object_list-notif_no = '100000356980'.
APPEND ls_object_list TO lt_object_list.
* Fill object list up structure
ls_object_list_up-processing_ind = 'X'.
APPEND ls_object_list_up TO lt_object_list_up.
CALL FUNCTION 'BAPI_ALM_ORDER_MAINTAIN'
TABLES
it_methods = lt_methods
it_header = lt_header
it_header_up = lt_header_up
it_objectlist = lt_object_list
it_objectlist_up = lt_object_list_up
return = lt_return .
For OBJECTLIST I would actually need something like an 'ADD' method. Any ideas are appreciated.
The following works for me:
ls_methods-refnumber = 1.
ls_methods-objecttype = 'OBJECTLIST'.
ls_methods-method = 'CREATE'.
ls_methods-objectkey = '000480000020'.
APPEND ls_methods TO lt_methods.
* Fill method structure
ls_methods-refnumber = 1.
ls_methods-method = 'SAVE'.
ls_methods-objecttype = ''.
ls_methods-objectkey = '000480000020'.
APPEND ls_methods TO lt_methods.
* Fill object list structure
ls_object_list-notif_no = '100000356980'.
APPEND ls_object_list TO lt_object_list.
* Fill object list up structure
ls_object_list_up-processing_ind = 'X'.
APPEND ls_object_list_up TO lt_object_list_up.
CALL FUNCTION 'BAPI_ALM_ORDER_MAINTAIN'
TABLES
it_methods = lt_methods
it_objectlist = lt_object_list
it_objectlist_up = lt_object_list_up
return = lt_return.

How to increment a variable name by 1 in Lua, and then set that as the variable name?

My current code is:
obj1 = object:new{x = math.random(1,92), y = math.random(1,92), roomx = 0, roomy = 0, symbol = "t", name = "Tree"}
obj2 = object:new{x = math.random(1,92), y = math.random(1,92), roomx = 0, roomy = 0, symbol = "t", name = "Tree"}
obj3 = object:new{x = math.random(1,92), y = math.random(1,92), roomx = 0, roomy = 0, symbol = "t", name = "Tree"}
And so on. Since they are all the same thing, I'd like to be able to generate a variable that I can increment the name by one, and then use a for loop to create a lot of them. Is there a way I can do that in Lua? Thanks!
You can use a table to hold the objects and add them using a for loop.
local objects = {}
--> This will create 20 objects
for i=1, 20 do
objects[i] = object:new{x = math.random(1,92), y = math.random(1,92), roomx = 0, roomy = 0, symbol = "t", name = "Tree"}
end

How to update all the variables when one variable is changed in a class in MATLAB?

I am writing a Multiplier class that multiplies its two parameters. If parameters are not given, default value of 1 is given.
Now when I update one variable, I do not get the exact product. My code is as below:
classdef Multiplier
properties (SetAccess = public, GetAccess = public)
first;
second;
end
properties(SetAccess = immutable, GetAccess = public)
product;
end
methods
function obj = Multiplier(varargin)
if nargin == 0
obj.first = 1;
obj.second = 1;
end
if nargin == 1
obj.first = varargin{1};
obj.second = 1;
end
if nargin > 1
obj.first = varargin{1};
obj.second = varargin{2};
end
obj.product = obj.first * obj.second;
end
end
end
k = Multiplier
k.first = 5
k.product -> This should return 5
You should make your product property Dependent. See this post for an example.