Update heap, stack and opcodes

This commit is contained in:
Werner
2021-11-29 20:43:59 -03:00
parent 03e43f39ce
commit 38236f0ad5
10 changed files with 396 additions and 180 deletions

View File

@ -12,215 +12,278 @@ pub const NOP: u8 = 0x00;
/// ```
pub const LDR: u8 = 0x01;
/// **0x02** - Save register in memory.
/// **0x02** - Load register from imediate value.
///
/// ```no_run
/// svr 0050 r1 // mem[0050] = r1
/// ldi r1 1 // r1 = 1
/// ```
pub const SVR: u8 = 0x02;
pub const LDI: u8 = 0x02;
/// **0x03** - Move register.
/// **0x03** - Store register in memory.
///
/// ```no_run
/// str 0050 r1 // mem[0050] = r1
/// ```
pub const STR: u8 = 0x03;
/// **0x04** - Store imediate value in memory.
///
/// ```no_run
/// sti 0050 1 // mem[0050] = 1
/// ```
pub const STI: u8 = 0x04;
/// **0x05** - Move register.
///
/// ```no_run
/// mov r1 r2 // r1 = r2
/// ```
pub const MOV: u8 = 0x03;
pub const MOV: u8 = 0x05;
/// **0x04** - The addition operator `+`.
/// **0x06** - Push register value on stack.
///
/// ```no_run
/// push r1 // sp = r1
/// ```
pub const PUSH: u8 = 0x06;
/// **0x07** - Pop stack and save in register.
///
/// ```no_run
/// pop r1 // r1 = sp
/// ```
pub const POP: u8 = 0x07;
/// **0x08** - Increment register.
///
/// ```no_run
/// inc r1 // r1 += 1
/// ```
pub const INC: u8 = 0x08;
/// **0x09** - Decrement register.
///
/// ```no_run
/// dec r1 // r1 -= 1
/// ```
pub const DEC: u8 = 0x09;
/// **0x0A** - Jump to address.
///
/// ```no_run
/// jmp 0050
/// ```
pub const JMP: u8 = 0x0A;
/// **0x0B** - The addition operator `+`.
///
/// ```no_run
/// add r1 r2 r3 // r1 = r2 + r3
/// ```
pub const ADD: u8 = 0x04;
pub const ADD: u8 = 0x0B;
/// **0x05** - The addition assignment operator `+=`.
/// **0x0C** - The addition operator `+`, with carry;
///
/// ```no_run
/// adc r1 r2 r3 r4 // r1 = r2 + r3 + r4
/// ```
pub const ADC: u8 = 0x0C;
/// **0x0D** - The addition assignment operator `+=`.
///
/// ```no_run
/// add r1 r2 // r1 += r2
/// ```
pub const ADD_ASSIGN: u8 = 0x05;
pub const ADD_ASSIGN: u8 = 0x0D;
/// **0x06** - The subtraction operator `-`.
/// **0x0E** - The subtraction operator `-`.
///
/// ```no_run
/// sub r1 r2 r3 // r1 = r2 - r3
/// ```
pub const SUB: u8 = 0x06;
pub const SUB: u8 = 0x0E;
/// **0x07** - The subtraction assignment operator `-=`.
//// *0x0F0x06** - The subtraction operator `-`, with carry;
///
/// ```no_run
/// suc r1 r2 r3 r4 // r1 = r2 - r3 + r4
/// ```
pub const SBC: u8 = 0x0F;
/// **0x10** - The subtraction assignment operator `-=`.
///
/// ```no_run
/// sub r1 r2 // r1 -= r2
/// ```
pub const SUB_ASSIGN: u8 = 0x07;
pub const SUB_ASSIGN: u8 = 0x10;
/// **0x08** - The multiplication operator `*`.
/// **0x11** - The multiplication operator `*`.
///
/// ```no_run
/// mul r1 r2 r3 // r1 = r2 * r3
/// ```
pub const MUL: u8 = 0x08;
pub const MUL: u8 = 0x11;
/// **0x09** - The multiplication assignment operator `*=`.
/// **0x12** - The multiplication assignment operator `*=`.
///
/// ```no_run
/// mul r1 r2 // r1 *= r2
/// ```
pub const MUL_ASSIGN: u8 = 0x09;
pub const MUL_ASSIGN: u8 = 0x12;
/// **0x0A** - The division operator `/`.
/// **0x13** - The division operator `/`.
///
/// ```no_run
/// div r1 r2 r3 // r1 = r2 / r3
/// ```
pub const DIV: u8 = 0x0A;
pub const DIV: u8 = 0x13;
/// **0x0B** - The division assignment operator `/=`.
/// **0x14** - The division assignment operator `/=`.
///
/// ```no_run
/// div r1 r2 // r1 /= r2
/// ```
pub const DIV_ASSIGN: u8 = 0x0B;
pub const DIV_ASSIGN: u8 = 0x14;
/// **0x0C** - The remainder operator `%`.
/// **0x15** - The remainder operator `%`.
///
/// ```no_run
/// rem r1 r2 r3 // r1 = r2 % r3
/// ```
pub const REM: u8 = 0x0C;
pub const REM: u8 = 0x15;
/// **0x0D** - The remainder assignment operator `%=`.
/// **0x16** - The remainder assignment operator `%=`.
///
/// ```no_run
/// rem r1 r2 // r1 %= r2
/// ```
pub const REM_ASSIGN: u8 = 0x0D;
pub const REM_ASSIGN: u8 = 0x16;
/// **0x0E** - Arithmetic negation `-`.
/// **0x17** - Arithmetic negation `-`.
///
/// ```no_run
/// not r1 r2 // r1 = -r2
/// ```
pub const NEG: u8 = 0x0E;
pub const NEG: u8 = 0x17;
/// **0x0F** -The bitwise AND operator `&`.
/// **0x18** -The bitwise AND operator `&`.
///
/// ```no_run
/// and r1 r2 r3 // r1 = r2 & r3
/// ```
pub const AND: u8 = 0x0F;
pub const AND: u8 = 0x18;
/// **0x10** - The bitwise AND assignment operator `&=`.
/// **0x19** - The bitwise AND assignment operator `&=`.
///
/// ```no_run
/// and r1 r2 // r1 &= r2
/// ```
pub const AND_ASSIGN: u8 = 0x10;
pub const AND_ASSIGN: u8 = 0x19;
/// **0x11** - The bitwise OR operator `|`.
/// **0x1A** - The bitwise OR operator `|`.
///
/// ```no_run
/// or r1 r2 r3 // r1 = r2 | r3
/// ```
pub const OR: u8 = 0x11;
pub const OR: u8 = 0x1A;
/// **0x12** - The bitwise OR assignment operator `|=`.
/// **0x1B** - The bitwise OR assignment operator `|=`.
///
/// ```no_run
/// or r1 r2 // r1 |= r2
/// ```
pub const OR_ASSIGN: u8 = 0x12;
pub const OR_ASSIGN: u8 = 0x1B;
/// **0x13** - The bitwise XOR operator `^`.
/// **0x1C** - The bitwise XOR operator `^`.
///
/// ```no_run
/// xor r1 r2 r3 // r1 = r2 ^ r3
/// ```
pub const XOR: u8 = 0x13;
pub const XOR: u8 = 0x1C;
/// **0x14** - The bitwise XOR assignment operator `^=`.
/// **0x1D** - The bitwise XOR assignment operator `^=`.
///
/// ```no_run
/// xor r1 r2 // r1 ^= r2
/// ```
pub const XOR_ASSIGN: u8 = 0x14;
pub const XOR_ASSIGN: u8 = 0x1D;
/// **0x15** - Logical negation `!`
/// **0x1E** - Logical negation `!`
///
/// ```no_run
/// not r1 r2 // r1 = !r2
/// ```
pub const NOT: u8 = 0x15;
pub const NOT: u8 = 0x1E;
/// **0x16** - The left shift operator `<<`.
/// **0x1F** - The left shift operator `<<`.
///
/// ```no_run
/// shl r1 r2 // r1 = r2 << 1
/// ```
pub const SHL: u8 = 0x16;
pub const SHL: u8 = 0x1F;
/// **0x17** - The left shift assignment operator `<<=`.
/// **0x20** - The left shift assignment operator `<<=`.
///
/// ```no_run
/// shl r1 // r1 <<= 1
/// ```
pub const SHL_ASSIGN: u8 = 0x17;
pub const SHL_ASSIGN: u8 = 0x20;
/// **0x18** - The right shift operator `>>`.
/// **0x21** - The right shift operator `>>`.
///
/// ```no_run
/// shr r1 r2 // r1 = r2 >> 1
/// ```
pub const SHR: u8 = 0x18;
pub const SHR: u8 = 0x21;
/// **0x19** - The right shift assignment operator `>>=`.
/// **0x22** - The right shift assignment operator `>>=`.
///
/// ```no_run
/// shr r1 // r1 >>= 1
/// ```
pub const SHR_ASSIGN: u8 = 0x19;
pub const SHR_ASSIGN: u8 = 0x22;
/// **0x1A** - The equality operator `==`.
/// **0x23** - The equality operator `==`.
///
/// ```no_run
/// eq r1 r2 r3 // r1 = r2 == r3
/// ```
pub const EQ: u8 = 0x1A;
pub const EQ: u8 = 0x23;
/// **0x1B** - The inequality operator `!=`.
/// **0x24** - The inequality operator `!=`.
///
/// ```no_run
/// neq r1 r2 r3 // r1 = r2 != r3
/// ```
pub const NEQ: u8 = 0x1B;
pub const NEQ: u8 = 0x24;
/// **0x1C** - The less than operator `<`.
/// **0x25** - The less than operator `<`.
///
/// ```no_run
/// lt r1 r2 r3 // r1 = r2 < r3
/// ```
pub const LT: u8 = 0x1C;
pub const LT: u8 = 0x25;
/// **0x1D** - The less than or equal to operator `<=`.
/// **0x26** - The less than or equal to operator `<=`.
///
/// ```no_run
/// le r1 r2 r3 // r1 = r2 <= r3
/// ```
pub const LE: u8 = 0x1D;
pub const LE: u8 = 0x26;
/// **0x1E** - The greater than operator `>`.
/// **0x27** - The greater than operator `>`.
///
/// ```no_run
/// gt r1 r2 r3 // r1 = r2 > r3
/// ```
pub const GT: u8 = 0x1E;
pub const GT: u8 = 0x27;
/// **0x1F** - The greater than or equal to operator `>=`.
/// **0x28** - The greater than or equal to operator `>=`.
///
/// ```no_run
/// ge r1 r2 r3 // r1 = r2 >= r3
/// ```
pub const GE: u8 = 0x1F;
pub const GE: u8 = 0x28;
/// **0xFF** - Halt execution.
///