• Home
  • :
  • Community
  • :
  • Blogs
  • :
  • PCB Design
  • :
  • BoardSurfers: Using Variables and Stacks in Allegro SKI…

PCB Design Blogs

  • All Blog Categories
  • Breakfast Bytes
  • Cadence Academic Network
  • Cadence Support
  • Computational Fluid Dynamics
  • CFD(数値流体力学)
  • 中文技术专区
  • Custom IC Design
  • カスタムIC/ミックスシグナル
  • 定制IC芯片设计
  • Digital Implementation
  • Functional Verification
  • IC Packaging and SiP Design
  • In-Design Analysis
    • In-Design Analysis
    • Electromagnetic Analysis
    • Thermal Analysis
    • Signal and Power Integrity Analysis
    • RF/Microwave Design and Analysis
  • Life at Cadence
  • Mixed-Signal Design
  • PCB Design
  • PCB設計/ICパッケージ設計
  • PCB、IC封装:设计与仿真分析
  • PCB解析/ICパッケージ解析
  • RF Design
  • RF /マイクロ波設計
  • Signal and Power Integrity (PCB/IC Packaging)
  • Silicon Signoff
  • Solutions
  • Spotlight Taiwan
  • System Design and Verification
  • Tensilica and Design IP
  • The India Circuit
  • Whiteboard Wednesdays
  • Archive
    • Cadence on the Beat
    • Industry Insights
    • Logic Design
    • Low Power
    • The Design Chronicles
Sanjiv Bhatia
Sanjiv Bhatia
30 Jun 2021

BoardSurfers: Using Variables and Stacks in Allegro SKILL

 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.

Using Stack in Allegro SKILL

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.

Using Variables in Allegro SKILL

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.

Global Variables

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=5
x2=10
procedure( 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

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=5
x2=10
procedure( 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)

The output of the above code is:

Conclusion

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 pcbbloggers@cadence.com.

Tags:
  • 17.4 |
  • programming |
  • BoardSurfers |
  • 17.4-2019 |
  • PCB design |
  • Allegro Skill |
  • SKILL |
  • Allegro |