SX/B Multiplication
jgjonola
Posts: 27
Hey Guys,· Is there a way to do multibyte multiplication using sx/b?· If I do this...
z·= 255 * 31... is there any way to get the real result?· If not, do you have an assembly work around?
Also, one other quick one (hopefully)· If a user enters (via a keypad) a 3 digit number, how do i take the 3 digits and make it 1 number.· like I enter 1,2,3 now i want to turn that into 123.· Any suggestions?· I was thinking first digit * 100 + second digit * 10 + 3rd digit.· Is there an easier way?
Thank you,
John Gjonola
Post Edited (jgjonola) : 9/27/2005 6:11:27 AM GMT
z·= 255 * 31... is there any way to get the real result?· If not, do you have an assembly work around?
Also, one other quick one (hopefully)· If a user enters (via a keypad) a 3 digit number, how do i take the 3 digits and make it 1 number.· like I enter 1,2,3 now i want to turn that into 123.· Any suggestions?· I was thinking first digit * 100 + second digit * 10 + 3rd digit.· Is there an easier way?
Thank you,
John Gjonola
Post Edited (jgjonola) : 9/27/2005 6:11:27 AM GMT
Comments
' Use: MAKE_ADDR theChar
' -- multiples 'theChar' by 32
MAKE_ADDR:
· eeLo = 0················· ' clear address
· eeHi = 0
· IF __PARAM1 > 0 THEN
··· ASM
····· MOV· eeLo, __PARAM1···' copy character value
····· MOV· __PARAM1, #5···· ' prep to shift 5 times
····· CLC
····· RL·· eeLo············ ' shift the low byte
····· RL·· eeHi··········· ·' shift high (use C)
····· DJNZ __PARAM1, $-2
··· ENDASM
· ENDIF
· RETURN
The point of showing this is that if you can find an assembly routine for what you want to do then you can add it as I have done.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
GET_VALUE:
· keyCount = 0
· theVal = 0
· DO
····key = SCAN_KEY
··· IF key = Enter THEN EXIT
··· theVal = theVal * 10
··· theVal = theVal + key
··· INC keyCount
· LOOP UNTIL keyCount = 3
· RETURN
This routine will allow up to three keys and can terminate with an enter key -- that way you can get one- or two-digit values.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
See, multi-byte math...·· ...it's the way of the future!·(grin) I·thinking of·some projectes·last night that could use it...
JG,
http://www.sxlist.com/techref/ubicom/lib/math/mul.htm·These are ASM routines, but you should be able to implement them in SX/B...
-Dan
Here is a routine to get a 16 bit result from multiplying two bytes:
DEVICE SX28,OSCXT1,OPTIONX,STACKX,TURBO
FREQ 4_000_000
A VAR BYTE ' Multiplicand
B VAR BYTE ' Multiplier
LSB VAR BYTE ' LSB of Product
MSB VAR BYTE ' MSB of Product
PROGRAM Start NOSTARTUP
Start:
· A = 255
· B = 31
· ASM ' LSB,MSB = A * B
··· MOV __PARAM1,A '·Copy multiplicand because the copy will get trashed
··· CLR MSB ' Start with all bits 0 execpt LSB.7 which is used as a counter flag to indicate we are done
··· MOV LSB,#128
· Mult_Loop:
··· RR __PARAM1 ' Rotate multiplicand
··· MOV W,B· '·Prepare·to add multiplier to Product MSB
··· SNC '·Only add if the carry is set
··· ADD MSB,W ' If carry was set add multiplier to MSB
··· RR MSB '·Rotate the whole product
··· RR LSB
··· JNC @Mult_Loop ' Repeat until that bit we set initially shows up
· ENDASM
· WATCH LSB,16,UDEC
END
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"SX-Video·Module" Now available from Parallax for only $28.95
http://www.parallax.com/detail.asp?product_id=30012
Product web site: www.sxvm.com
Available now... SX-Video OSD module $59.95 www.sxvm.com
"I'm a man, but I can change, if I have to, I guess"
Red Green
Post Edited (Bean (Hitt Consulting)) : 9/27/2005 6:59:52 PM GMT
Perhaps you could add some comments to your code to explain why it is doing what it is doing.
Thanks, PeterM
Thanks again,
John Gjonola
What's a comment ? Ha Ha just kidding...
Okay, I'll edit the post and add comments...
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"SX-Video·Module" Now available from Parallax for only $28.95
http://www.parallax.com/detail.asp?product_id=30012
Product web site: www.sxvm.com
Available now... SX-Video OSD module $59.95 www.sxvm.com
"I'm a man, but I can change, if I have to, I guess"
Red Green
·
I noticed you used the SX/B keyword "LOOP" in your code and I fear that this would cause an error in actual use (I checked, it does). You may want to edit that to "Mult_Loop."
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
See thats's why I don't comment stuff.... [noparse];)[/noparse]
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"SX-Video·Module" Now available from Parallax for only $28.95
http://www.parallax.com/detail.asp?product_id=30012
Product web site: www.sxvm.com
Available now... SX-Video OSD module $59.95 www.sxvm.com
"I'm a man, but I can change, if I have to, I guess"
Red Green
·
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
You wouldn't have an ASM 16bit by 8bit <i>divide</i> laying around also would you? I tried the one from SXlist but unless all quotients are $FF, I think its not working. Getting the 32bit by 16 bit divide sounds like overkill at this point but maybe I have to go there.
I need to divide 10K by a number between 25 and 200 for a pulse to frequency conversion.
Thanks
Paul
Update: I found another 16bit/8bit division on SXList made by Nikolai Golovchenko. This dropped into a ASM/ENDASM perfectly. Lesson learned: If you dont see it on SXList..keep digging..lol
Post Edited (Paul) : 10/9/2005 1:45:08 AM GMT
I'm trying to see why the 16/8 would not work and the only thing I can think of is that it may be dependant on the carryx option setting... I'll play with it a bit.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
---
James Newton, Host of SXList.com
james at sxlist,com 1-619-652-0593 fax:1-208-279-8767
SX FAQ / Code / Tutorials / Documentation:
http://www.sxlist.com Pick faster!
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
---
James Newton, Host of SXList.com
james at sxlist,com 1-619-652-0593 fax:1-208-279-8767
SX FAQ / Code / Tutorials / Documentation:
http://www.sxlist.com Pick faster!
I tried the one marked "16 bits by 8 from Lou Zher" first. Then found the /math/div16by8to16_16.htm (with 16 bit decimal not remainder) from Nickolai. Strangely I dont see it listed anymore. hmmm. Found it! It's at the bottom of /math/basic.html... not in /math/div.htlm. (you might want to move it to div.html [noparse];)[/noparse] )
I'm afraid I don't know anything about carryx or y or z..I can barely carry a tune. This is my first attempt to prog the SX other than running Parallax demo download and blinking lights.
It sure gives one an appreciation for the BS2 and something as simple as "DEBUG DEC3 10000/166"
http://www.sxlist.com/techref/ubicom/lib/math/div
Thanks for letting me know.... Not sure how it got that way...
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
---
James Newton, Host of SXList.com
james at sxlist,com 1-619-652-0593 fax:1-208-279-8767
SX FAQ / Code / Tutorials / Documentation:
http://www.sxlist.com Pick faster!