Before discussing Virtual Machine programming it should be noted that you should be programming in {high-level}, and not in the assembly language unless you are trying optimize code to be faster than the code the compiler will generate.
Basic Program Structure
All programs must contain a main section and an end statement. This program prints “Hello World!” on the screen.
main: movs sax "Hello World!" mov ix 3 int 6 end
Subroutines, and variable declarations can appear above and below the main procedure. When a program is loaded into memory, the IP is set to the location of the main procedure. A program can have multiple end statements, but it can only have one main procedure.
Simple Data Types
There are four types of variables allowed in AyersLabs Assembly: integers,arrays,floats,and strings.
| Declaration | Explanation | |
|---|---|---|
| num x 5 | creates an integer called x and assigns it the value 5. | |
| flt point 4.5 | creates an float point number called point and assigns it the value 4.5. | |
| str hello “Hello World!” | creates a string called hello and assigns it the value “Hello World!”. | |
Complex Data types
| Declaration | Explanation |
|---|---|
| dim x 5 | creates an array that can hold five integers. |
| dims x 5 | creates an array that can hold five strings. |
| dimf x 5 | creates an array that can hold five floating point numbers. |
Arithmetic
| Instruction | Definition |
|---|---|
| add | Add two non-floating point integers/register |
| sub | Subtract two non-floating point integers/register |
| mul | Multiply two non-floating point integers/register |
| div | Divide two non-floating point integers/register |
| mod | Modules of two non-floating point numbers/register |
| addf | Add two floating point numbers/register |
| subf | Subtract two floating point numbers/register |
| divf | Divide two floating point numbers/register |
| mulf | Mutiply two floating point numbers/register |
| neg | Negate a number/register |
| inc | Increment a register by one |
| dec | Decrement a register by one |
For example usage please see the arithmetic tutorial section.
Bit Shifting
| Instruction | Definition |
|---|---|
| shl | Shift two non-floating point numbers/register left |
| shr | Shift two non-floating point numbers/register right |
For example usage please see the bit shifting tutorial section.
Data Transfer
| Instruction | Definition |
|---|---|
| mov | Move integer |
| movf | Move floating point |
| movs | Move string |
| xchg | Exchange |
| lea | Load effective address |
| lla | Load label address |
For example usage please see the data transfer tutorial section.
Conversions
| Instruction | Definition |
|---|---|
| csi | Convert string to integer |
| cis | Convert integer to string |
| cif | Convert integer to float |
| cfs | Convert float to string |
| csf | Convert string to float |
For example usage please see the conversion tutorial section.
String
| Instruction | Definition |
|---|---|
| adds | Combine two strings/registers |
For example usage please see the string tutorial section.
Comparison
| Instruction | Definition |
|---|---|
| cmp | Compare two integers |
| cmps | Compare two strings |
| cmpf | Compare two floating point numbers |
| test | Tests jump condition based on last comparison |
For example usage please see the comparison tutorial section.
Flags
| Instruction | Definition |
|---|---|
| pushf | Push all flags onto stack |
| popf | Pop all flags from stack |
Logical
| Instruction | Definition |
|---|---|
| and | Logical AND |
| or | Logical OR |
| not | Logical NOT |
| xor | Logical XOR |
For example usage please see the logical operation tutorial section.
Looping
| Instruction | Definition |
|---|---|
| loop | loop until complete |
| loopnz | loop while not zero |
| loopz | loop while zero |
| loope | loop while equal |
| loopne | loop while not equal |
For example usage please see the loop tutorial section.
Processor
| Instruction | Definition |
|---|---|
| halt | Enter halt state |
Stack
| Instruction | Definition |
|---|---|
| pop | Pop integer stack |
| push | Push integer stack |
| pops | Pop String stack |
| pushs | Push string stack |
| popfp | Pop Floating point stack |
| pushfp | push floating point stack |
| pushf | push all flags onto stack |
| popf | pop all flags off stack |
| pusha | push all register onto stack |
| popa | pop all registers off stack |
For example usage please see the stack tutorial section.
Transfer (Conditional)
| Instruction | Definition |
|---|---|
| je | Jump if equal |
| jne | Jump if not equal equal |
| jl | Jump if less than |
| jg | Jump if greater than |
| jle | Jump if less than or equal |
| jge | Jump if greater than or equal |
For example usage please see the transfer (conditional) tutorial section.
Transfer (Uncondition)
| Instruction | Definition |
|---|---|
| jmp | Uncondition jump |
| call | call a procedure |
| ret | return |
| int | interrupt |
For example usage please see the transfer (unconditional) tutorial section.
Registers offer fast read / write access to data. Whenever possible you should use the 48 general purpose registers for storing data as the other registers are often used for internal manipulation of data. For example when passing data when a program calls interrupt you should assume the data passed into the non-general purpose registers will be altered.
Integer Registers
This registers can only only integer values.
| Instruction | Definition |
|---|---|
| ax | Arithmetic |
| bx | general purpose/arithmetic |
| cx | count register |
| dx | general purpose |
| ix | interrupt register |
| ip | instruction pointer |
| cs | code segment |
| ds | data segment |
| reint | general purpose/arithmetic |
Special Integer Registers
These are integer registers that are read-only. They are increased or decreased whenever data is pushed or popped from the system stack.
| Instruction | Definition |
|---|---|
| bp | base pointer (int) |
| bps | base pointer (string) |
| bpf | base pointer (float) |
Floating Point Registers
These registers can hold floating point values and integer values.
| Instruction | Definition |
|---|---|
| fax | Arithmetic |
| fbx | general purpose/arithmetic |
| fcx | general purpose/arithmetic |
| fdx | general purpose/arithmetic |
| reflt | general purpose/arithmetic |
String Registers
These registers can only hold strings.
| Instruction | Definition |
|---|---|
| sax | general purpose |
| sbx | general purpose |
| scx | general purpose |
| sdx | general purpose |
| restr | general purpose |
Flag Registers
| Instruction | Definition |
|---|---|
| tf - Test flag | The result of the last test condition. 1 if test was true, and 0 if test was false |
| if - Interrupt flag | This turns the interrupts or off. The default is 1. |
| ef - Error flag | This register contains the most recent error code. |
| cf - Comparison flag | This register contains the result of the most recent cmp operation.1 = equal 2 = not equal 3 = less than 4 = greater than |
| nf - Negative flag | This flag is set to 1 if last compare was between a negative number |
General Purpose Registers
| Instruction | Definition |
|---|---|
| ri1 - ri16 | Integer Registers |
| rf1 - rf16 | Floating Pointer Registers |
| rs1 - rs16 | String Registers |
Interrupts are mini programs that are hardcoded into the virtual machine that interrupt the flow of a program to perform an action. Once an interrupt program has finished executing control will be passed back to the program, and any results returned will be stored in the registers. Interrupts are broken down by they over arching function.
| Interrupt | Description |
|---|---|
| INT1 | SYSTEM |
| INT2 | KEYBOARD |
| INT3 | MOUSE |
| INT4 | FILE ACCESS |
| INT5 | FILE SYSTEM |
| INT6 | OUTPUT |
| INT7 | STRING |
| INT8 | AUDIO |
| INT9 | NETWORK |
| INT10 | BOOTSTRAP |
| INT11 | MEMORY |
| INT12 | ERROR HANDLER |
| INT13 | DEBUG |
| INT14 | CD-ROM |
| INT15 | Power |
| INT16 | Math |
| INT17 | BIOS |
| INT18 | Date & Time |
| INT19 | Graphics |
| INT21 | System Tools |
| INT22 | VMOS |
| INT90 | CRASH |