
;R1 = Vinit (Smallest Possible Value)
;R2 = Vend (Largest Possible Value)
;R3 = StepN (Step Number that we want a value for)
;R4 = NumSteps (Total number of steps between Vinit and Vend)
;R0 = OUTPUT
;Psuedo code: OUTPUT = Vinit + (((Vend - Vinit) / NumSteps)) * StepN)
;This function assumes that Vinit will always be smaller than Vend
;None of these OPCodes require R0-R4, if you have variables declared for these values, then
;replace Rx with the corrisponding variable name (i.e. "MOV A, R2" could be re-written "MOV A, Vend")
;If any of the input values never change, then hard set the values, and don't use variables
;(i.e. if Vend is always 200, then "MOV A, R2" could be re-written "MOV A, #200")
FIND_STEP_VALUE:
	PUSH	ACC	;Save ACC on the stack, remove this line if the value of A is not important
	PUSH	B	;Save B on the stack, can be removed
	PUSH	PSW	;Save PSW on the stack (C,OV, etc are altered by this function), can be removed
	CLR	C
	MOV	A, R2	;Loading A with Vend for the following SUBB
	SUBB	A, R1	;Start with the inner-most parenthesis, Psuedo Code (Vend - Vinit), A stores the answer
	MOV	B, R4	;Loading B with NumSteps for the following DIV
	DIV	AB	;Move out to the next parenthesis, Completed Psuedo Code ((Vend - Vinit) / NumSteps), A stores the answer
	MOV	B, R3	;Loading B with StepN for the following MUL
	MUL	AB	;Move out to the next parenthesis, Completed Psuedo Code (((Vend - Vinit) / NumSteps) * StepN), A stores the answer
	ADD	A, R1	;Last required operation adding our answer back to Vinit
	MOV	R0, A	;Save our answer to a RAM address
	POP	PSW	;remove this line if the corrisponding PUSH is removed
	POP	B	;remove this line if the corrisponding PUSH is removed
	POP	ACC	;remove this line if the corrisponding PUSH is removed
	RET
