How can I declear mips array? - mips

I would like to declare
int A[] = {1,2,3,4,5,6,7,8,9,10} in c language as mips.
Here's my code, please give me a solution.
A: .word 1,2,3,4,5,6,7,8,9,10
Is it right?

yes, it's right, then you can use A as the addresss, and A+offset to get the position of every element.

Related

Simulink block to generate points from equation

I need help in Simulink, I am looking for a way to generate an array as the outputs from Simulink block like if t=0:1:10s then x = 2sin(t), I know only of the block that gives constant value of x. This is the model block:
Highlighted blocks give constants; I want to replace them with any block that would generate an array using equation such as instead of x=50 it will give x=2sin(t)
I have found the answer. The block I was looking for is 'fcn'. It is only available in Matlab 2020a and below, that's why I couldn't find it (I have 2021a). Hope it helps anybody else.
This is what it looks like, you can just write your equation in it

AS3 Dynamic variable naming

Is dynamic variable naming like this possible in ActionScript 3?
for (var xz=0;xz<10;xz++){
var this['name' + xz]:Number = xz;
}
You should use an array for this kind of list of variables.
While you can create properties dynamically, you usually want to avoid it. Especially in your case, where the actual identifier of each variable is not a String, but a number. So why not use something that does exactly that: identify its elements by a number? And that's exactly what an array does.
code example:
var xzs:Array = [];
for (var xz:uint = 0; xz < 10; xz++){
xzs.push(xz);
}
Short answer is: no, you can't declare at runtime typed properties.
Long answer is: kinda.
If you want to create new typed properties you'll have to store them in a Vector<>.
Anything else would let you do it but untyped, dynamic class, store in object, store in array, etc ...
Yes, it sure is - AS3 comes from ECMA script, so this is setting a property to an object (in this case it's this). So you can dynamically set properties. But you are a little bit wrong about how to do it - there is no need to use var, because you don't declare it, you set it. It's like using:
this.propertyName = 'value';
From now on, this will have propertyName equal to 'value'. Therefore you should just use:
this['name' + xz] = xz;
That's all!
Edit: as BotMaster mentioned - if you are using classes and you want to dynamically add properties, the class must be set as dynamic. Most of the commonly used ones are already dynamic (as Aaron mentioned :)).
I didn't go into much details as I think you simply need to do this on your timeline. If not - please specify this in your question so that you can get more accurate answer than this one. The same goes if your new property needs to be typed (can't think of any point wanting this) - you should see BotMaster's answer :)

Freefem++: Solving poisson equation with numerical function

I am using Freefem++ to solve the poisson equation
Grad^2 u(x,y,z) = -f(x,y,z)
It works well when I have an analytical expression for f, but now I have an f numerically defined (i.e. a set of data defined on a mesh) and I am wondering if I can still use Freefem++.
I.e. typical code (for a 2D problem in this case), looks like the following
mesh Sh= square(10,10); // mesh generation of a square
fespace Vh(Sh,P1); // space of P1 Finite Elements
Vh u,v; // u and v belongs to Vh
func f=cos(x)*y; // analytical function
problem Poisson(u,v)= // Definition of the problem
int2d(Sh)(dx(u)*dx(v)+dy(u)*dy(v)) // bilinear form
-int2d(Sh)(f*v) // linear form
+on(1,2,3,4,u=0); // Dirichlet Conditions
Poisson; // Solve Poisson Equation
plot(u); // Plot the result
I am wondering if I can define f numerically, rather than analytically.
Mesh & space Definition
We define a square unit with Nx=10 mesh and Ny=10 this provides 11 nodes on x axis and the same for y axis.
int Nx=10,Ny=10;
int Lx=1,Ly=1;
mesh Sh= square(Nx,Ny,[Lx*x,Ly*y]); //this is the same as square(10,10)
fespace Vh(Sh,P1); // a space of P1 Finite Elements to use for u definition
Conditions and problem statement
We are not going to use solve but we ll handle matrix (a more sophisticated way to solve with FreeFem).
First we define CL for our problem (Dirichlet ones).
varf CL(u,psi)=on(1,2,3,4,u=0); //you can eliminate border according to your problem state
Vh u=0;u[]=CL(0,Vh);
matrix GD=CL(Vh,Vh);
Then we define the problem. Instead of writing dx(u)*dx(v)+dy(u)*dy(v) I suggest to use macro, so we define div as following but pay attention macro finishes by // NOT ;.
macro div(u) (dx(u[0])+dy(u[1])) //
So Poisson bilinear form becomes:
varf Poisson(u,v)= int2d(Sh)(div(u)*div(v));
After we extract Stifness Matrix
matrix K=Poisson(Vh,Vh);
matrix KD=K+GD; //we add CL defined above
We proceed for solving, UMFPACK is a solver in FreeFem no much attention to this.
set(KD,solver=UMFPACK);
And here what you need. You want to define a value of function f on some specific nodes. I'm going to give you the secret, the poisson linear form.
real[int] b=Poisson(0,Vh);
You define value of the function f at any node you want to do.
b[100]+=20; //for example at node 100 we want that f equals to 20
b[50]+=50; //and at node 50 , f equals to 50
We solve our system.
u[]=KD^-1*b;
Finally we get the plot.
plot(u,wait=1);
I hope this will help you, thanks to my internship supervisor Olivier, he always gives to me tricks specially on FreeFem. I tested it, it works very well. Good luck.
The method by afaf works in the case when the function f is a free-standing one. For the terms like int2d(Sh)(f*u*v), another solution is required. I propose (actually I have red it somewhere in Hecht's manual) an approach that covers both cases. However, it works only for P1 finite elements, for which the degrees of freedom are coincided with the mesh nodes.
fespace Vh(Th,P1);
Vh f;
real[int] pot(Vh.ndof);
for(int i=0;i<Vh.ndof;i++){
pot[i]=something; //assign values or read them from a file
}
f[]=pot;

Use Textfield as a Variable Possible ? don't know

I am currently trying to do the following.
I have 2 Textfields, One is Taken from the Dataset (in the Pictures below i have used 400 as a plain number to make things more straight Forward).
now what i want is for one of them to be used as a Variable (not sure if this is the right Term)
i want the value that Text1 is given to automatically be divided from Text2.
Below you will see the Text1 (named Divide) Properties.
and this is Text2 where I am trying to use the Value of Text 1:
I Know everything about having to Convert The field into an Int or some Number, and everything,
what i don't get is how I am supposed to use Textfield1 in Textfield2 ?
Thanks for your Answers in Advance.
What programming language is that?
if it's C# you can do something like:
int x = int.Parse(Text2.Text);
this will convert the string of Text2 (Textfield) to an integer,
if it's java it would be like:
int x = Integer.parseInt(Text2.getText());
But if the user enter some character that isn't a number the problem will crash.
Here is the Answer, thanks again to Visakh16
=400/ReportItems!Divide.value
and here the link: Use Textfield as a Variable Possible ? - Social MSDN

Need help in adding functionality to MIPS single cycle datapath?

I'm trying to add functionality to these datapaths so that it can read the following instruction:
ADDNEW X, Y, Z
if (Y > Z) X = Y+ Z
else X = MEM[Y+Z]
Not really sure where to start.. so any hints are appreciated. I think I need to rewrite the result of the slt somewhere to tell it which way to go.. but not sure how? Yes is for homework so not expecting answers.. just hopefully a direction. Thank you..
second http://www.utdallas.edu/~cantrell/ee4304/Pipe-data+control.jpg
The top design is a single cycle and the bottom design is a pipeline design.