Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
04/24/09 03:15
Read: times


 
#164818 - A possible start
Responding to: ???'s previous message
Here's something to start you off. Quick and dirty, hasn't been tested.

;R0=BUFFER TO STORE VALUES
;R1=START
;R2=END
;R3=NUMBER OF STEPS
;CLOBBERS ACC,R4,B,C
;ASSUMES R2>R1
EVEN_STEP:
	CLR	C
	MOV	A, R2
	SUBB	A, R1			;GETTING THE DIFFERENCE BETWEEN START AND END
	MOV	B, R3
	DIV	AB			;DIVIDE TO GET THE DIFFERENCE FOR EACH STEP
	MOV	R4, A			;SAVE THE STEP DIFFERENCE IN R4
	MOV	A, R1			;LOAD START INTO A
EVEN_STEP_ADD_LOOP:
	ADD	A, R4			;ADD STEP DIFFERENCE TO LAST STEP VALUE
	MOV	@R0, A			;SAVE THE STEP VALUE INTO OUR BUFFER
	INC	R0			;INCREMENT BUFFER POINTER
	DJNZ	R3, EVEN_STEP_ADD_LOOP	;WASH, RINSE AND REPEAT
	RET

 


The challenge I've left for you is that this routine won't step evenly with non-round division (i.e. last number saved in the buffer might be less than desired end value). The DIV function leaves the remainder in B, so that's a good place to start. Look up ADDC and see if that will help you. And also think about recursive functions if you need really good precision and timing isn't important.

Good luck!

List of 19 messages in thread
TopicAuthorDate
Values interpolation            01/01/70 00:00      
   A possible start            01/01/70 00:00      
      The Brezingham Line Drawing algorithm            01/01/70 00:00      
         http://en.wikipedia.org/wiki/Bresenham%27s_line_algorithm ?            01/01/70 00:00      
            Good method            01/01/70 00:00      
               Integer Digital Differential Analyzer            01/01/70 00:00      
   Simple scheme...            01/01/70 00:00      
      Further optimization            01/01/70 00:00      
         You are absolutely right, of course,...            01/01/70 00:00      
   Having a hard time trying to understand :(            01/01/70 00:00      
      Clarification Needed            01/01/70 00:00      
         Even more confused now            01/01/70 00:00      
            Another Shot            01/01/70 00:00      
               code            01/01/70 00:00      
                  Provided Code            01/01/70 00:00      
                     Maybe this            01/01/70 00:00      
                        Give this a try...            01/01/70 00:00      
            Look it up            01/01/70 00:00      
      Now, we have a hard time to understand...            01/01/70 00:00      

Back to Subject List