1. SASM Instructions¶
File: sasm_instructions.h
Author: Soham Metha
Date: January 2025
1.1. Table of Contents¶
1.2. Opcode Enumeration¶
The Opcode enum defines all supported instructions in SASM.
| Opcode | Description |
|---|---|
| NOP | No operation |
| HLT | Halt |
| ADD | Addition |
| SUB | Subtraction |
| MUL | Multiplication |
| DIV | Division |
| EQL | Equality |
| POP | Pop |
| PSH | Push |
| DUP | Duplicate |
| JMP | Jump |
| JNZ | Jump if not zero |
| JIP | Jump if positive |
1.3. Data Structures¶
1.3.1. Instruction Structure¶
Represents a single SASM instruction, consisting of an opcode and an operand.
typedef struct {
Opcode type; /**< The opcode of the instruction */
Word operand; /**< The operand of the instruction */
} Instruction;
1.3.2. Program Structure¶
Represents a complete SASM program, including instructions and metadata.
typedef struct {
Instruction instructions[PROGRAM_CAPACITY]; /**< Array of instructions */
Word instruction_count; /**< Number of instructions */
Word instruction_size; /**< Size of each instruction in bytes */
} Program;
1.4. Function Declarations¶
1.4.1. Stack Operations¶
-
Push to Stack
Pushes a value onto the stack.
-
Equality Operation
Compares the top two values of the stack for equality.
-
Pop from Stack
Pops a value from the stack.
-
Duplicate Value
Duplicates a value on the stack based on the operand.
1.4.2. Instruction Execution¶
- Execute an Instruction Executes a single instruction in the virtual machine.
1.4.3. Opcode Conversion¶
-
Convert Opcode to String
Converts an opcode to its string representation.
-
Convert String to Opcode
Converts a string to its corresponding opcode.