This is a playground of assembly language Inspired by TIS-100 minimalistic Architecture
The main registers for all operations
MOV ACC GPR # Copy Values from ACC to GPR
PUSH ACC # Copy Values from ACC and Push it to stack memory
POP # Take value from stack memory and put it to ACC
SWP # Swap the value of ACC <> BAKUsually for storing temporary values
Warning: Directly Inaccessible, can only be accessed via
SWPinstruction
SWP # Swap the value of ACC <> BAK, store the value of ACC to BAK, while
# simultaneously send the initial value of BAK to ACC
SAV # Copy the value from ACC to BAKSelf-described, can be accessed like ACC but will not change except wanted to
MOV ACC GPR # Copy Values from ACC to GPR
MOV GPR ACC # Copy Values from GPR to ACC
PUSH GPR # Copy Values from GPR and Push it to stack memoryInterface to interact with display device, can be manipulated like ACC
# Assume this is the first time we are manipulating DSP register
MOV 0x00ff DSP # 1st Value: coordinate 255 from the top left of the display
MOV 0x00ff DSP # 2nd Value: Red value
MOV 0x00ff DSP # 3nd Value: Green value
MOV 0x0000 DSP # 4th Value: Blue value
# this 4 sequence of writing to DSP means:
# show Yellow pixel -- since RGB is (255, 255, 0) -- at column 255, row 0 of the displayRepresent how many elements currently exist in the Stack Memory, cannot be manipulated can only be read
MOV STC ACC # Copy Values from STC to ACCRepresent which line of program are currently being executed, cannot be manipulated can only be read
MOV PRC ACC # Copy Values from STC to ACCNo Operation, literally does nothing, usually for pad a single instruction
Register Manipulation, copy data from one place to another
MOV <SRC> <DST>SRC: the source of data to copy from, will not change after operationDST: the destination, the data copied fromSRCwill be stored here
Copy a value from one place to stack memory
PUSH <SRC>SRC: the source of data to copy from and push into the stack
Getting a value and remove it from stack to ACC
PUSHSwap value of ACC and BAK
SWPSaving value from ACC to BAK
SAVAdd value from Source to ACC
ADD <SRC>This means
ACC = ACC + SRC
Subtract value from Source to ACC
SUB <SRC>This means
ACC = ACC - SRC
Negate value of ACC
NEG <SRC>This means
ACC = -ACC or ACC = ACC * -1
Invert ACC
NOTThis means
ACC = ~ACC
Logical And between SRC and ACC
AND <SRC>This means
ACC = SRC & ACC
Logical Or between SRC and ACC
OR <SRC>This means
ACC = SRC | ACC
Logical Exclusive-Or between SRC and ACC
XOR <SRC>This means
ACC = SRC ^ ACC
Logical Not-And between SRC and ACC
NAND <SRC>This means
ACC = ~(SRC & ACC)
Logical Not-Or between SRC and ACC
NOR <SRC>This means
ACC = ~(SRC | ACC)
Logical Not-Exclusive-Or between SRC and ACC
XNOR <SRC>This means
ACC = ~(SRC ^ ACC)
Logical Shift-Right ACC with SRC amount
SHR <SRC>This means
ACC = ACC >> SRC
Logical Shift-Left ACC with SRC amount
SHL <SRC>This means
ACC = SRC << ACC
Jump to a label unconditionally
JMP <LABEL>Jump to a label if ACC is Zero
JEZ <LABEL>Jump to a label if ACC is Not Zero
JNZ <LABEL>Jump to a label if ACC is Greater than Zero
JGZ <LABEL>Jump to a label if ACC is Less than Zero
JLZ <LABEL>Jump to an instruction with and OFFSET
JRO <OFFSET>Halt the program, stop executing
HALT- have maximum address of
0xFFFF, and the stack pointer is0x0000 0x0000is the top of the stack, and0xFFFFis the bottom of the stack0x0000is the first element of the stack, and0xFFFFis the last element of the stackPUSHoperation will put the value to the top of the stackPOPoperation will put the value from the top of the stack toACCSTCregister will show how many elements currently exist in the stack memory
To interact with the display, you can use the DSP register, which is a special register that can be manipulated like ACC. The display is a 256x256 pixel display, and each pixel can be manipulated by writing to the DSP register.
however, the display is not a 2D array, but a 1D array of starting from 0x0000 through 0xFFFF.
0x0000is the top left corner of the display, and0xFFFFis the bottom right corner of the display
therefore, to write to display you need to write 4 times to the DSP register, which is:
- 1st Value: coordinate from the top left of the display
- 2nd Value: Red value
- 3nd Value: Green value
- 4th Value: Blue value
every 4 sequence of writing to DSP means the display will parse the input and show the pixel accordingly.
with this kind of limitation, colloquially it is required to clean the sequences first before writing to the display, so that the display will not show the previous value.
this is some of the examples of how to clean up sequences:
_CLEAN_DSP:
JMP _CLEAN_DSP_1
_CLEAN_DSP_4:
# Assume 4 sequence is written to DSP before this
MOV 0x0000 DSP # 1st Value: coordinate 0 from the top left of the display
MOV 0x0000 DSP # 2nd Value: Red value
MOV 0x0000 DSP # 3nd Value: Green value
MOV 0x0000 DSP # 4th Value: Blue value
_CLEAN_DSP_3:
# Assume 3 sequence is written to DSP before this
MOV 0x0000 DSP # 4th Value: Blue value
JMP _CLEAN_DSP_4
_CLEAN_DSP_2:
# Assume 2 sequence is written to DSP before this
MOV 0x0000 DSP # 3rd Value: Green value
MOV 0x0000 DSP # 4th Value: Blue value
JMP _CLEAN_DSP_3
_CLEAN_DSP_1:
# Assume 1 sequence is written to DSP before this
MOV 0x0000 DSP # 2nd Value: Red value
MOV 0x0000 DSP # 3rd Value: Green value
MOV 0x0000 DSP # 4th Value: Blue value
JMP _CLEAN_DSP_2