Intel® Simics® Simulator for Intel® FPGAs: User Guide

ID 784383
Date 4/01/2024

A newer version of this document is available. Customers should click here to go to the newest version.

Document Table of Contents

5.3.4. Intel® Simics® Simulator CLI Variables and Operations

The Intel® Simics® simulator CLI provides the ability to define variables that you can later use in the same Intel® Simics® simulation session, similarly to how the environment variables are used in a Linux terminal.

Intel® Simics® simulator variables are defined and accessed using the $ symbol as a prefix of the variable name. Similarly to Python programming, the variables can hold any kind of type of value including Boolean, integer, float, string, list or a combination of them.

To show the value of a variable, use the echo command or enter the variable at an Intel® Simics® CLI prompt. Some examples of declaration and use of variables are as follows (all examples use the Intel® Simics® command-line interface):
# Integer type

simics> $myIntVar = 100
simics> echo $myIntVar
# Float type
simics> $myFloatVar = 1.2
simics> echo $myFloatVar
# Operation Integer and Float types
simics> $myVar2 = $myIntVar + $myFloatVar
simics> echo $myVar2
# String
simics> $myStrVar= "Hello World"
simics> $myStrVar2 = $myStrVar
simics> echo $myStrVar2
Hello World
# List type
simics> $myList = [7, 4, [2.5, -3.2], "hello", "world"]
simics> echo $myList 
[7, 4, [2.5, -3.2], "hello", "world"]
simics> $myList[2][0]
# String operation
simics> $myNewStrVar =  $myList[3]+ " " + $myList[4]
simics> echo $myNewStrVar
hello world
# String and integer operation
simics> $myNewStrVar = $myNewStrVar + $myList[0]
simics> echo $myNewStrVar
hello world7
# Integer and String operation
simics> $myIntVar = $myIntVar + $myStrVar
simics> echo $myIntVar
100Hello World
# Boolean type variables
simics> $myBoolVar1 = TRUE
simics> $myBoolVar2 = FALSE
simics> $myBoolVar3 = $myBoolVar1 or $myBoolVar2
simics> echo $myBoolVar3
simics> $myBoolVar3 = $myBoolVar1 and $myBoolVar2
simics> echo $myBoolVar3

The following operations are supported on the Intel® Simics® CLI:

  • Basic math operations: - , +, /, *
  • Modulo operation: %
  • Bit wise operation (C- style): << , >>, &, |, ^
  • Comparison: == , <=, >=, <, >
  • String concatenation: +
  • String formatting: “string with %d %s ” % [ value 1 value 2]
Use parentheses to handle operation precedence and to force a string to be evaluated as an Intel® Simics® simulator command.
# Intel Simics simulator CLI 
# String formatting

simics> $myValue = 40723
simics> $myStr = "World"
simics> $myStrTest = "Hello %s %d" % [$myStr, $myValue]
simics> $myStrTest
"Hello World 40723"

# Using parentheses to force interpretation as a command
# Text in parentheses is interprested as a command.
# The return value of the command in parenthese is passed to the command outside
# the parentheses.

# Compare the output of the following commands:

simics> sim.log-level
Current log levels:
Lvl  Object
  1  sim

simics> echo sim.log-level

simics> echo (sim.log-level)

When you use numbers in variables, the Intel® Simics® simulator CLI also supports several base formats using the 0<x/b/o> prefix. The CLI also supports displaying grouped digits using the _ character to separate the digit groups. For example:

  • Decimal: 987_654_321
  • Binary: 0b0110_1110_0011
  • Octal: 0o76_5_43_21
  • Hex: 0xabcd_ef12_9876

You can also define the base of the output information in the Intel® Simics® simulator CLI with the following command:

output-radix <base> <grouping>
Where the <base> can be 2, 8, 10, or 16. The following examples show the effect of the output-radix command on displaying a value:
# Intel Simics simulator CLI 
simics> $myvalue = 40723
simics> output-radix
The current output-radix is 10.

simics> echo $myvalue

simics> output-radix 16 4
simics> echo $myvalue

simics> output-radix 8 2
simics> echo $myvalue

simics> output-radix 2 4
simics> echo $myvalue

simics> output-radix 10
simics> echo $myvalue

Using Intel® Simics® simulator CLI variables can be helpful when creating scripts to automated sequences of actions. For more information about scripting in Intel® Simics® simulator, refer to Intel Simics Scripting.