??? 04/29/09 23:10 Read: times |
#164945 - Another Shot Responding to: ???'s previous message |
Hopefully the large number of comments will help clarify the code and allow you to change it to suit your needs. If I'm completely off-base, then I'm sorry I've wasted your time.
;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 To use this code, do as follows ;this code gives 10 steps from 30-50 MOV R1, #30 MOV R2, #50 MOV R4, #10 MOV R3, #10 LOOP: LCALL FIND_STEP_VALUE ;DO SOMETHING WITH THE RETURNED VALUE IN R0 DJNZ R3, LOOP This is all completely untested and written in a hurry. It should only be used if you fully understand what's going on. |
Topic | Author | Date |
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 |