/cpu_scala

Primary LanguageScalaMIT LicenseMIT

cpu_scala

work in progress...

ASM reference

Native instructions

NOP

Do nothing

LD / LDZ / LDNZ

Load unconditionally / load if Zero flag is set (1) / load if Zero flag is reset (0)

NOTE: all LD instructions can be also used as LDZ and LDNZ variants. This also applies to aliases of load instruction, i.e. jump, output and input.

LD AL, byte / LDAL byte

Load AL (low byte of A/R3 register) with a immediate byte

LD AH, byte / LDAH byte

Load AH (high byte of A/R3 register) with a immediate byte

LD Rx, Ry

Load value from Rx to Ry, i.e. Rx --> Ry

NOTE: LD R0, Rx is a jump instruction

LD Rx, R0 / JMP Rx

Jump to address stored in Rx

LD Mx, Ry

Load value from memory at address stored in Rx to Ry, i.e. (Rx) --> Ry

LD Rx, My

Load value from Rx to memory at address stored in Ry, i.e. Rx --> (Ry)

LD Rx, Py / OUT Rx, Py

Output a value from Rx to output port y

LD Px, Ry / IN Rx, Py

Input a value from input port x to Rx

ADD Rx, Ry

Add value of Ry to Rx, i.e. Rx += Ry, set flags accordingly

SUB Rx, Ry

Subtract value of Rx from Ry, i.e. Rx -= Ry, set flags accordingly

CMP Rx, Ry

Compare value of Rx to Ry, only set flags

AND Rx, Ry

Binary AND Rx with Ry, i.e. Rx &= Ry, set flags accordingly

OR Rx, Ry

Binary OR Rx with Ry, i.e. Rx |= Ry, set flags accordingly

XOR Rx, Ry

Binary XOR Rx with Ry, i.e. Rx ^= Ry, set flags accordingly

INC Rx

Increase value of Rx, set flags accordingly

DEC Rx

Decrease value of Rx, set flags accordingly

TBD: SHL, SHR, FLB

Macros

LDA word

Execute LDAL and LDAH on low and high bytes of given word

LDR word, Rx

Execute LDA to load a word into A / R3 and then load it to Rx

NOTE: this macro overwrites A / R3

JMPI address

Execute LDA to load an address into A / R3 and then jump to the given address

NOTE: this macro overwrites A / R3

CALL address

Execute LDA to load an address into A / R3, push return address to stack and jump to the given address.

NOTE: this macro overwrites A / R3

RET

Pop return address from stack to A / R3 and then jump to the return address.

NOTE: this macro overwrites A / R3

PUSH Rx

Decrease stack pointer R1 and load value of Rx to the memory at new stack pointer.

POP Rx

Load value from memory at current stack pointer R1 to Rx, increase stack pointer.