Skip to content

Variable management

PaulNowak36 edited this page Feb 23, 2024 · 4 revisions

Variable management in the Virtual Processor's assembly language involves declaring, initializing, and manipulating variables for data storage and retrieval.

var instruction

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.
  • 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'
    

Types of variables

Integer

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.

   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 " ".

   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.

   var color, 0xFE84AC ;We declare the color pink
   draw color ; we display the content of the color

Binary

In AT2, binary values are represented by a sequence of digits, where each of them can be either 0 or 1. The prefix "0b" is required to declare one.

   var letter, 0b01011000 ;We declare the character 0b01011000(X)
   draw letter; we display the content of the letter