Tesla-A16D16 Processing Unit pg.2

  • Sam_Hayzen
    27th Feb 2018 Member 1 Permalink
    Tesla-A16D16 Processing Unit
    
    Instruction Data Structure:
    	The higher two nybbles(0xXX--) of the 16-bit instruction are dedicated to the Operation Code and Condition Code.
    		The higher of these two nybbles is the four-bit Operation Code. (0xX---)
    		The lower of these two nybbles is the four-bit Condition Code.  (0x-X--)
    
    	The lower two nybbles(0x--XX) of the 16-bit instruction are dedicated to operation's parameters.
    		If the operation has a parameter of "a8" (Address 8-Bit) [Ex:JR a8], both nybbles(0x--XX) are used as immediate 8-bit data.
    		If the operation has a parameter of rg1,rg2 (Two registers with 4-bit index numbers) [Ex: LD rg1,rg2], the high nybble(0x--X-) is used as the index of the first register, and the low nybble(0x---X) is used as the index of the second register.
    		If the operation has a parameter of rg1 (One register with a 4-bit index) [Ex: Inv rg1], the high nybble(0x--X-) is used as the index of the first register, and the low nybble(0x---X) goes unused.
    		If the Operation has a parameter of rg1,d4 (One register with a 4-bit index, and an immediate 4-bit value) [Ex: Add rg1,d4], the high nybble(0x--X-) is used as the index of the first register, and the low nybble(0x---X) is used as 4-bit immediate data.
    		If the Operation has a parameter of rg1,d16 (One register with a 4-bit index, and an immediate 16-bit value) [Ex: LD rg1,d16], the high nybble(0x--X-) is used as the index of the first register, and the low nybble(0x---X) goes unused. Note, if these parameters are in a command, it means that the 16-bit data is sourced from the next byte in memory, not the byte the instruction is in.
    
    	Examples:
    		LD R8,R2 [LD rg1,rg2]
    			This would load the contents of Register 2 into Register 8
    			The byte for this command would be: 5 0 8 2
    				The first nybble is 5 because the opcode for LD rg1,rg2 is 5
    				The second nybble is 0 because the instruction is unconditional
    				The third nybble is 8 because the selected first register is Register 8
    				The fourth nybble is 2 because the selected second register is register 2 
    
    		LD nc,R6,(RE) [LD rg1,(rg2)]
    			This would load the contents of the memory address of Register E into Register 6 if the Carry Flag is not set
    			The byte for this command would be: 7 3 6 E
    				The first nybble is 7 because the opcode for LD rg1,(rg2) is 7
    				The second nybble is 3 because the instruction has a Not Carry (nc) condition
    				The third nybble is 6 because the selected first register is Register 6
    				The fourth nybble is E because the selected second register is register E 
    
    		Add R0,3 [Add rg1,d4]
    			This would add 3 to the value of Register 0 and loads it back into Eegister E
    			The byte for this command would be: A 0 0 3
    				The first nybble is A because the opcode for Add rg1,d4 is A
    				The second nybble is 0 because the instruction is unconditional
    				The third nybble is 0 because the selected first register is Register 0
    				The fourth nybble is 3 because the data immediate value is 3
    
    		JR STOP,3E [JR a8]
    			This would set the lower two nybbles of the Program Counter to 3E once the processor received a START pulse, or the Start Button was pressed
    			The byte for this command would be: 8 F 3 E
    				The first nybble is 8 because the opcode for JR a8 is 8
    				The second nybble is F because the instruction waits for a START pulse to execute
    				The third nybble is 3 because the high nybble of the 8-Bit address is 3
    				The fourth nybble is E because the low nybble of the 8-Bit address is E
    
    		Nop [Nop]
    			No Operation
    			The byte for this command would be: 0 - - -
    				The first nybble is 0 because the opcode for Nop is 0
    				The second nybble is irrelevant because the instruction will do nothing, regardless of if it its condition is met or not (Unless its condition is "STOP", 0xF, which will always halt the processor)
    				The third nybble is irrelevant because Nop does not have parameters
    				The fourth nybble is irrelevant because Nop does not have parameters
    
    		JP z,R4 [JP rg1]
    			This command would load Register 4 into the Program Counter if the Zero Flag is set
    			The byte for this command would be: 9 4 4 -
    				The first nybble is 9 because the opcode for JP rg1 is 9
    				The second nybble is 4 because the instruction has a Zero (z) condition
    				The third nybble is 4 because the selected first register is Register 4
    				The fourth nybble is irrelevant because JP rg1 only needs one 4-Bit parameter
    
    
    		LD R6,0x3FFF [LD rg1,d16]
    			This command would load the value 0x3FFF into register 6
    			The byte for this command would be: 4 0 6 -
    				The first nybble is 9 because the opcode for JP rg1 is 9
    				The second nybble is 4 because the instruction has a Zero (z) condition
    				The third nybble is 4 because the selected first register is Register 4
    				The fourth nybble is irrelevant because only the rg1 parameter of LD rg1,d16 is stored in the instruction iself. The d16 parameter is stored in the byte after the instruction.
    
    Example Snippets:
    
    
    	Increment Register 1
    		|Address
    		|    |Value
    		|    |    |Mneumonic
    		|0000|A011|Add R1,1
    	
    	Decrement Register 1
    		|Address
    		|    |Value
    		|    |    |Mneumonic
    		|0000|F010|Inv R1		;convert R1 to Two's Compliment (Negative Number)
    		|0001|A011|Add R1,1		;Add (subtract) one
    		|0002|F010|Inv R1		;convert R1 back into a normal number
    		
    	Add Register 1 and Register 2
    		|Address
    		|    |Value
    		|    |    |Mneumonic
    		|0000|B012|Add R1,R2
    	
    	Subtract Register 2 from Register 1
    		|Address
    		|    |Value
    		|    |    |Mneumonic
    		|0000|F010|Inv R1		;convert R1 to Two's Compliment (Negative Number)
    		|0001|C012|Add R1,R2	;Add (subtract) Register 2 to (from) Register 1, which is now a negative number.
    		|0002|F010|Inv R1		;convert R1 back into a normal number
    	
    	Multiply Register 1 by Register 2
    		|Address
    		|    |Value
    		|    |    |Mneumonic
    		|0000|4000|LD R0,
    		|0001|0000|0000			;Load 0x0000 into Register 0. Note how 0x0000 is in the byte -after- the instruction. This byte is not executed by the processor and is skipped.
    		|0002|F010|Add R1,0		;Check if R1 is zero
    		|0003|A011|JR z,08		;If R1 equals zero, stop and return zero
    		|0004|F010|Inv R1		;Invert R1 for counting down
    		|0005|A011|Add R0,R2	;Add R2 for every one value in R1
    		|0006|A011|Add R1,1		;Decrement R1
    		|0007|F010|JR nz,05 	;Loop
    		|0008|A011|Nop			;End, result will be in R0
    		
    Assembler:
    	The Tesla-A16D16 has a assembler meant to assist in writing programs
    	
    	To write a command, simply configure the parameters on the assembler and spark the mneumonic for the instruction you wish to enter.
    	Parameters are pulled from the fields in the top left of the screen, or from the Register Pointers
    	To edit the parameters in the top left, spark CLR and enter a 4-digit, 2-digit, or 1-digit hexidecimal number in the keypad to the left.
    	The "Current Address" counter simply keeps track of the total bytes written (in order to remember places to jump to). Warning! This counter has no effect on the assembler. Going back to an address you've already written to will not overwrite it. Every entered command will always be placed after the last.
    	
    	Commands are written in the order they're entered.
    	Once your program is done, fold/wrap the strip of assembled code to fit into a disk and simply paste it in.
    	
    

    Page one

    Edited once by poodiepie. Last: 28th Feb 2018