Re: 34S SUM PROD change request ccccc >= fff Message #2 Posted by Paul Dale on 1 Oct 2011, 8:14 p.m., in response to message #1 by Egan Ford
This is somewhat limited by the definition of DSE unfortunately.
Here is the sum and product code as it currently exists in the firmware image. It is just a plain old keystroke program. Feel free to submit a patch :)
The stack will always be four levels deep when this code is run and registers 04 and flags 014 are freely available.
Then again, I could look into adding DSL and ISE as instructions.
 Pauli
/**************************************************************************/
/* Sigma and products
* Register use:
* 0 I
* 1 product/sum
* 2 carry for sum
* 3 saved I
*/
LBL 99 /* Entry: SUMMATION */
XEQ entry
SPEC?
JMP sum_product_okay
STO 00
STO 03 /* Save for LastX*/
IP /* First function call is separate*/
FILL /* to avoid Kahan summing from zero*/
XEQUSR /* six extra instructions save nine*/
SPEC? /* from executing*/
JMP sum_product_nan
STO 01
iC 0
STO 02
JMP sum_entry
sum_loop:: RCL 00
IP
FILL
XEQUSR
SPEC?
JMP sum_product_nan
RCL 02
ENTER[^]
RCL+ 01
ENTER[^]
RCL 01
RCL Z
x[<>]y
[cmplx]STO 01
sum_entry:: DSE 00
JMP sum_loop
JMP sum_product_okay
LBL 98 /* Entry: PRODUCT */
XEQ entry
SPEC?
JMP sum_product_okay
STO 00
STO 03
IP /* First function call is separate*/
FILL /* to avoid a multiply*/
XEQUSR
SPEC?
JMP sum_product_nan
STO 01
JMP product_entry
product_loop:: RCL 00
IP
FILL
XEQUSR
SPEC?
JMP sum_product_nan
STO[times] 01
product_entry:: DSE 00
JMP product_loop
sum_product_okay:: RCL 03
STO L
iC 0
FILL
RCL 01
JMP exit
sum_product_nan:: RCL 03
sum_product_error:: STO L
iC 0
FILL
# NaN
JMP exit
