Sunday, November 15, 2020

HP 41C and DM41: Operations by Test, Messages, Block Storage

 HP 41C and DM41: Operations by Test, Messages, Block Storage  


The programs are inspired from a great calculator resource, "Calculator Tips & Routines Especially For The HP-41C/41CV", edited by John Dearing (see source below).   


Operations by Test


One of the tips presented is the selection of one of two opposite arithmetic operations based on a comparison between X and Y values.  This tip was provided by Bill Kolb (tip 2-7).  They are:


X?Y

CHS  (subtract if test is true)

+   (add if test is false)


X?Y

1/X  (divide if the test is true)

*  (multiply if the test is false)


X?Y

1/X   (take the root if the test is true)

Y↑X  (take the power if the test is false)


The following programs uses the test X<Y:


TESTAS:  X<Y  (subtract, y - x),  X≥Y (adding, y + x)


(^T represent the beginning of an alpha string)


01 LBL^T TESTAS

02 X<Y?

03 CHS

04 + 

05 END


Example:  

45, 13, XEQ TESTAS returns 32  (45 - 13)

13, 45, XEQ TESTAS returns 58  (13 + 45)


TESTMD:  X<Y  (divide, y/x),  X≥Y (mulitply, y * x)


01 LBL^T TESTMD

02 X<Y?

03 1/X

04 * 

05 END


Example:  

45, 13, XEQ TESTMD returns 3.4615  ( ≈ 45 / 13)

13, 45, XEQ TESTMD returns 585  (13 * 45)


TESTPR:  X<Y  (root, y^1/x),  X≥Y (power, y^x)


01 LBL^T TESTPR

02 X<Y?

03 1/X

04 Y↑X 

05 END


Example:  

49, 3, XEQ TESTPR returns 3.6593  ( ≈ 49 ^ 1/3)

3, 49, XEQ TESTPR returns 2.3930E23  (≈ 3 ^ 49)


Messages


With the use of AVIEW during a loop, you can display a loop up to 12 characters while the loop is running.   A CLD (clear display) is added after the loop's completion to clear the alpha display and show the stack. (tip 2-25)


The program TESTSUM adds a message while the 41C is summing numbers from 1 to X.   While this is not the most efficient way to tackle the problem, this illustrates the use of messages.  


01 LBL^T TESTSUM

02 STO 01

03 0

04 STO 02

05 LBL 01   // loop begins

06 RCL 01

07 ST+ 02

08 ^T ADDING...  // message

09 AVIEW   // display the message

10 DSE 01

11 GTO 01

12 CLD  // clear display

13 RCL 02

14 END


Example:

50, XEQ TESTSUM  

Display: ADDING..., then 1275


Block Storage


You can use indirect storage and the stack to store a constant in a block of consecutive storage registers.  A sample loop:


LBL %%

STO IND Y

ISG Y

GTO %%


Where %% is a label, and the loop variable is B.EEE  (B:  beginning register, E:  ending register) stored in this case, Stack Y.  (tip 10-1)


The program LOADBLK, prompts the user enter the value, beginning register number, and ending register number.


01 LBL^LOADBLK

02 ^T VALUE

03 PROMPT

04 STO Z     // keystrokes:  [ STO ]  [ . ]  ( Y )

05 ^T R%% BGN?

06 PROMPT

07 ^T R%% END?

08 PROMPT

09 1E3

10 /

11 +

12 STO Y  

13 RDN   // R↓

14 X<>Y

15 LBL 01

16 STO IND Y   // keystrokes:  [ STO ] [ shift ] [ . ] ( Y )

17 ^T STORING...    // message

18 AVIEW

19 ISG Y    // keystrokes:  [ shift ] ( ISG ) [ . ] ( Y )

20 GTO 01

21 ^T DONE

22 AVIEW

23 PSE

24 CLD

25 END


Try this:

Store π in R00 to R03 and e^1 in R04 to R07.

 

Results:  (Fix 4)

R00:  3.1416

R01:  3.1416

R02:  3.1416

R03:  3.1416

R04:  2.7183

R05:  2.7183

R06:  2.7183

R07:  2.7183


Source:


Dearing, John.  "Calculator Tips & Routines Especially for the HP-41C/41CV"  Corvallis Software, Inc.   Corvallis, OR.  1981 


Link on HP41.org (account needed):  http://www.hp41.org/LibView.cfm?Command=View&ItemID=320



Eddie


All original content copyright, © 2011-2020.  Edward Shore.   Unauthorized use and/or unauthorized distribution for commercial purposes without express and written permission from the author is strictly prohibited.  This blog entry may be distributed for noncommercial purposes, provided that full credit is given to the author. 


TI 84 Plus CE: Consolidated Debts

TI 84 Plus CE: Consolidated Debts   Disclaimer: This blog is for informational and academic purposes only. Financial decisions are your ...