Google FeedBurner is phasing out its RSS-to-email subscription service. While we are currently working on the implementation of a new system, you may experience an interruption in your email subscription service.
Please stay tuned for further communications.
Get email delivery of the Cadence blog featured here
In our previous blog post, we discussed how to count the number of pins and rename reference designators using the SKILL codes available in the Allegro SKILL Code Library. In this blog post, let’s focus on how to create a stack and define global or local variables in the SKILL code.
Stack is a data structure in programming languages where elements are added and removed in a Last In, First Out (LIFO) order. Adding or removing data from a stack is done from the top. To add and remove the push and pop processes are used, respectively.
In Allegro SKILL, a stack is a list that works using the two functions pushf and popf. You can use these functions to add and remove elements from the top of the list.
To understand the use of these functions, let us consider the following example where you first create a stack myStack and then add two elements 2 and 1 to the stack using the pushf function.
myStack=list(3 4 5 6)printf("Stack is %L\n" myStack)pushf(2 myStack)printf("After pushing 2 Stack is %L\n" myStack)pushf(1 myStack)printf("After pushing 1 Stack is %L\n" myStack)
Now that you know how to add elements to a stack, let’s see how to remove elements using the popf function. The following example shows how you can remove elements from myStack using the popf function.
printf("Before popping Stack is %L\n" myStack) elem=popf(myStack) printf("After popping: Element removed from stack is %L and Stack is %L\n" elem myStack) elem=popf(myStack) printf("After popping again: Element removed from stack is %L and Stack is %L\n" elem myStack)
The following image displays the output of the above two SKILL codes:
Also, note the use of printf function to display the elements stored in myStack.
Like other programming languages, Allegro SKILL also uses variables to store values. The scope of these variables can be local or global. Let’s look at how to use global and local variables in a SKILL code.
All variables in a SKILL code are, by default, considered as global and their values can be accessed in any part of the code.
To understand this, see the following code snippet where x1 and x2 are global variables and their values can be accessed inside any procedure.
x1=5x2=10procedure( sum(number1 number2) printf(“Inside x1 is %d x2 is %d sum is %d\n” x1 x2 x1+x2) x1=50 x2=100)printf("Before sum x1 is %d x2 is %d \n" x1 x2)sum(1 2)printf("After sum x1 is %d x2 is %d \n" x1 x2)
The output of the above code is:
Local variables, on the other hand, in a SKILL code need to be explicitly defined. These variables can be declared using the let and prog functions. The let function allows you to define temporary values to local variables. Unlike global variables, local variables are recognized only within the let statement and their values cannot be accessed outside let. The prog function allows an explicit loop to be written have multiple return points.
For example, in the following code, x1 and x2 are local variables and their initial values are nil as they are defined locally in a procedure.
x1=5x2=10procedure( sum_with_local(number1 number2)let( (x1 x2) printf("Inside sum_with_local before assignment x1 is %L x2 is %L \n" x1 x2 ) x1=number1 x2=number2 printf("Inside sum_with_local x1 is %d x2 is %d sum is %d\n" x1 x2 x1+x2)))printf("Before sum_with_local x1 is %d x2 is %d \n" x1 x2)sum_with_local(1 2)printf("After sum_with_local x1 is %d x2 is %d \n" x1 x2)
That’s all there is to it! Just use these simple functions to define variables and stacks in your SKILL code and you are all set! If you want to try these functions in detail, you can refer to the Scope of Global and Local variables in Allegro SKILL and How to use Stack in Allegro SKILL articles.
Note: The above link can only be accessed by Cadence customers who have a valid login ID for https://support.cadence.com.
Do SUBSCRIBE to be updated about upcoming blogs. If you have any topic you want us to cover first or any feedback, you can write to us at email@example.com.