Skip to content

Logical and arithmetic operations

Guillaume DERAMCHI edited this page Feb 20, 2024 · 5 revisions

Logical and arithmetic operations form the core of computational functionalities in the Virtual Processor's assembly language, enabling a wide array of mathematical and logical tasks.

Arithmetic instructions

Arithmetic operations include addition, subtraction, multiplication, and division, crucial for data manipulation and calculations.

Syntax and usage

  • Addition (add): add rgX, Y
  • Subtraction (sub): sub rgX, Y
  • Multiplication (mul): mul rgX, Y
  • Division (div): div rgX, Y

Function

  • Performs arithmetic operations between registers and other operands (immediate values or variables).

Binary code and error check

  • Varies based on the specific operation and the operand types.
  • Error checks include the validation of operand existence and special conditions like division by zero.

Examples

add rg1, rg2   ; Adds the values in rg1 and rg2
sub rg1, 5     ; Subtracts 5 from the value in rg1
mul rg1, var1  ; Multiplies rg1 by the value in var1
div rg1, rg2   ; Divides the value in rg1 by the value in rg2

## Logical instructions

Logical operations such as XOR, AND, OR, and NOT are used for bitwise logical manipulations.

### Syntax and usage

- **XOR (`xor`)**: `xor rgX, Y`
- **AND (`and`)**: `and rgX, Y`
- **OR (`or`)**: `or rgX, Y`
- **NOT (`not`)**: `not rgX, Y`

### Function

- Executes bitwise logical operations between registers and other operands.

### Binary code and error check

- The binary code varies depending on the specific operation and operands.
- Error checks ensure the validity of the operands involved in the operations.

### Examples

```assembly
xor rg1, rg2   ; Performs XOR between rg1 and rg2
and rg1, 7     ; Performs AND between rg1 and the value 7
or rg1, var1   ; Performs OR between rg1 and the value in var1
not rg1, rg2   ; Performs NOT on the value in rg1 and stores it in rg2

Clone this wiki locally