16 bit multiply in PASM - another question
Hello,
I have been working in PASM for a few months now and I really like it.· I can handle the basic stuff pretty good but cannot seem to grasp how to use the example multiplication and division routines referenced in the manual (Appendix B, Math samples and Function tables).
It appears they have to be treated as a subroutine and called which I have not figured out how to do.· Does someone know of an example program that is VERY simple in nature that takes a couple of variables and performs the multiplication on them?·
Ultimately, what I need to do is square two variables.· Both variables will be able to fit in 16 bit vars so it looks like the multiplication routine would be best suited.· However, expecting to do division in PASM at some point in time, I hope to learn how to use both of those routines at the same time.
Thanks
Chris
Post Edited (Chris_D) : 3/12/2010 11:26:14 PM GMT
I have been working in PASM for a few months now and I really like it.· I can handle the basic stuff pretty good but cannot seem to grasp how to use the example multiplication and division routines referenced in the manual (Appendix B, Math samples and Function tables).
It appears they have to be treated as a subroutine and called which I have not figured out how to do.· Does someone know of an example program that is VERY simple in nature that takes a couple of variables and performs the multiplication on them?·
Ultimately, what I need to do is square two variables.· Both variables will be able to fit in 16 bit vars so it looks like the multiplication routine would be best suited.· However, expecting to do division in PASM at some point in time, I hope to learn how to use both of those routines at the same time.
Thanks
Chris
Post Edited (Chris_D) : 3/12/2010 11:26:14 PM GMT

Comments
Of course you have to define the LONGs to hold your numbers and x, y and the temporary variable t that multiply uses.
enter mov x, someNumber_1 'Set x parameter of multiply to some number mov y, someNumber_2 'Set y parameter to some other number call #multiply 'Do the multiply mov result, y 'Result is in y '' Multiply x[noparse][[/noparse]15..0] by y[noparse][[/noparse]15..0] (y[noparse][[/noparse]31..16] must be 0) ' on exit, product in y[noparse][[/noparse]31..0] ' multiply shl x,#16 'get multiplicand into x[noparse][[/noparse]31..16] mov t,#16 'ready for 16 multiplier bits shr y,#1 wc 'get initial multiplier bit into c :loop if_c add y,x wc 'if c set, add multiplicand to product rcr y,#1 wc 'put next multiplier in c, shift prod. djnz t,#:loop 'loop until done multiply_ret ret 'return with product in y[noparse][[/noparse]31..0] someNumber_1 long 1234 someNumber_2 long 5678 result long 0 x long 0 y long 0 t long 0If you are multiplying by small constant (< 9 bits) value put it directly in the mov instruction e.g.
mov someNumber, #42
Don't forget the example multiply in the manual is for positive numbers only.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
For me, the past is not over yet.
Thanks very much for responding.· That is exactly what I needed and more.· I completely forgot about the positive only values.· I suspect that I can work that out in the rest of the code without too much trouble though.
Thanks again!
Chris
If an example value is needed and example would be 3500 x 3500
Thanks
Chris
Thanks much for answering my question (and the follow up before I even asked it)!
Knowing that the time is a constant helps a lot as I work through a new program I am writing.· It will be a time-critical program and knowing the times of all the "little things" is of great importance.
Thanks again
Chris