-
Notifications
You must be signed in to change notification settings - Fork 0
Variable management
PaulNowak36 edited this page Feb 22, 2024
·
4 revisions
Variable management in the Virtual Processor's assembly language involves declaring, initializing, and manipulating variables for data storage and retrieval.
Syntax and usage
-
Syntax:
var name, value
- Function: Declares a variable with a given name and initializes it with a value.
-
Binary code:
- For numeric values:
1001 1000 0101 1001
(var id),1100 1000 0000 0001
,1101 0000 0000 1001
(Op code:1 0011
) - For string values: Binary code sequence includes the variable ID, size, and data.
- For numeric values:
-
Error check:
- Avoid redeclaration of existing variables.
- Adhere to size constraints (not exceeding 256 bytes).
Example
-
Declaring a numeric variable:
var myVar, 10 ; Declares variable 'myVar' with an initial value of 10
-
Declaring a string variable:
var myString, "Hello" ; Declares a string variable 'myString'
An integer is a whole number represented in binary format. It is a fundamental data type used in programming to store numerical values without fractional parts. Integers can be either signed or unsigned, depending on whether they include negative values or not.
var myNumber, 12 ; Declares an integer variable 'myNumber'
### Character
A character represents a single unit of text or symbol, typically using the ASCII(American Standard Code for Information Interchange) values. We need ' ' to declare one.
```assembly
var myChar, 'c' ; Declares an character variable 'myChar'
### String
A string is a sequence of characters used to represent text. To declare one, you need to use the " ".
```assembly
var myString, "wikipage" ; Declares an string variable 'myString'
### Hexadecimal
It defines the lexical convention for using hexadecimal numbers used in many programming languages, like in AT2. First, we need the prefix "Ox" to declare one.
```assembly
var color, 0x
(TBD)
### Binary
(TBD)