How Do I Divide in ASM
tom90
Posts: 55
Hey All,
I am trying to add another cog onto some code I wrote for an A/D that will average the values.
I have tried to get started by just adding up five numbers (1, 2, 3, 4, 5) and trying to divide by
five, but have had no luck in figuring out how to divide.
Anybody out there with some advice or a good divide routine?
Thanks
Tom
I am trying to add another cog onto some code I wrote for an A/D that will average the values.
I have tried to get started by just adding up five numbers (1, 2, 3, 4, 5) and trying to divide by
five, but have had no luck in figuring out how to divide.
Anybody out there with some advice or a good divide routine?
Thanks
Tom
Comments
Here's a thread with a link in the first message: http://forums.parallax.com/showthread.php?p=572669
The most obvious solution is to sample over powers of two (2, 4, 8, 16, ...)
Nick
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Never use force, just go for a bigger hammer!
The DIY Digital-Readout for mills, lathes etc.:
YADRO
Whats wrong?
Thanks
Tom
Change Total to y and then change x to Total. Then put "mov y,#5" before the "mov t,#16".
I changed my code to what you said, and my output is still 0
Anymore words of wisdom?
Thanks
Tom
[noparse][[/noparse]code]
mov y, #5 ' divisor is 5
shl y, #16 ' shift it left into high order bits
[noparse][[/noparse]code]
The other is that Total will be filling up with bits as you do this but I suspect that may be how the routine works.
Thanks for all of the help guys, but this still just wont work.
Are all of my variables defined properly?· I am not exactly sure what should be defined as a long, and should should be defined with [noparse][[/noparse]res 1].
Any other hints you can give me?
Thanks Again,
Tom
I just picked deSilva's example (that he picked from somewhere else) and it worked.
It's a good strategy -when developing software- to start with snippet, test, verify and understand them- and then integrate them into a whole.
Nick
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Never use force, just go for a bigger hammer!
The DIY Digital-Readout for mills, lathes etc.:
YADRO
Could you post the code you have working so i can compare the two?
Thanks
Tom
I suspect your remainder is killing you. What results are you actually getting on the debug?
See if that helps
-Parsko
All I keep getting for output is 0.
Tom
It was the variables y and t not being assinged a value that was doing it.
Thanks
Tom
Oh, yes! It matters terribly
THis is a specific syntax, alligning the label to a specific size. ALL THREE names Y, T, and H0000FFF share the same cell, which is the cause of the problem...
BTW... Aribas debugger PASD should have helped you all along and out of that problem...
Also, try removing and adding the "and" reoutine (to remove the remainder) to see the results. They should jump from something that makes sense (like 3), to something that clearly doesn't make sense (like 456,845,239)!
-Parsko
Dean
'###################################### SPAD BLOCK 5 ####################
'##
Code nop 'Start your assembly language program here! '##
mov Total,A1
add Total,A2
add Total,A3
add Total,A4
add Total,A5
mov dividend,Total
mov divisor,#5
call #divide 'Divide Total / 5
str1 byte "Answer ",0
mov debugVar,#str1
call #debugStr 'Send string str1 to the terminal
mov debugVar,quotient
call #debugDec 'Send decimal quotient to the terminal
mov debugVar,#13
call #debugChar 'Send carriage return to the terminal
mov debugVar,#4
call #debugDelay 'Delay 4 quarter seconds or 1 second
jmp #Code 'Repeat
A1 long 1
A2 long 2
A3 long 3
A4 long 4
A5 long 5
Total long 0
fit