converting register to program mem



#4

Hello there,

does someone have a solution for that problem:

Converting currencies:
a user has to enter some money-amounts. For example, the user keys in one amount, and then executes label A to store the number. The user has to enter about 40 money amounts to be stored. Then the user enters the value to multiply the numbers with into the X-Register and executes label B.

The numbers have to be stored in the memory Registers of a hp11c (and I want to use 10 at most).

The order of the number is important, (either LIFO or FIFo)

Any suggestions?

Klaus


#5

Hi Klaus,

Not to be flippant, but why do you want to do this? A database or even a spreadsheet would be so much more efficient....

Is this exercize just for fun?

#6

Hi, Klaus;

I'd like to get closer to the problem itself; may I?

Quote:
The user has to enter about 40 money amounts to be stored. Then the user enters the value to multiply the numbers with into the X-Register and executes label B.
When you mention "amount", will it be the amount you enter in LBL A? And may this amount be changed? And if it is changed, will this changing be counted as a new entry or only values keyed in prior to [GSB][B] are counted as entry data?
Quote:
The numbers have to be stored in the memory Registers of a hp11c (and I want to use 10 at most).
After the tenth register is used, will the next value ovewrite the earliest one? As you mention FIFO/LIFO being important, what is the best choice?

Also, will you need to read them as well?

I'm interested on trying, but I'd like to know some more about your ideas...d8^)

Cheers.

Luiz (Brazil)

Edited: 30 Aug 2004, 4:29 p.m.


#7

Hi!
If the user wants to convert the amounts 10.50, 100.25, 1000, he does the following:

10.5
[f] [A]
100.25
[f] [A]
1000
[f] [A]

To convert the values, the user enters the factor:

3.14159
[f] [B]

Let´s assume, the values don`t exceed 1000 and do not have more than 2 decimal places.

It´s not a concrete problem I have, it´s an example. You can store xxxxxxxxxxE99 in a register, but mostly it´s integers less than a million. What a waste.
I am thinking of developing a small program for pushing and popping numbers into a register, and any ideas are welcome!
Thank you so far!
Klaus


#8

I think you will need indirect addressing to do that and I don't think the 11C is capable of indirect addressing.


#9

Hi Chan and Klaus

Actually the 11c does have indirect addressing--that is what the "(i)" and "I" are for. You can indirectly address all the registers----but unlike the 41, you must use the "I" variable for the address ( the 41 allows you to use any variable for indirection address control).

#10

Hi, Klaus;

let's see if this helps a bit. In time: all text below assumes the HP11C is not in USER mode. If you want to use it in USER mode, suppress the [f] prefix key before [A], [B], [C], [D] and [E] keys.

The following program does what you want to do, but you must consider some facts:

1 - your called "factor" is stored in register R0;

2 - register contents from R1 to R.0 (the eleventh register available, and the tenth register in the block R1-R.0) are multiplied by the factor each time the factor is updated, and this happens when you press [f][B] (or [GSB][B]);

3 - I added two labels so you can see the registers contents in two ways either sequentially (LBL C)or randomly (LBL D). If you want a sequence, press [f][C] and the current contents are shown from R1 to R.0 (index is briefly shown); each time the calculator stops with the current value, press [R/S] for the next one. If you want a random check, key in the number of the register you want to see and press [f][D].

4 - When you are about to restart storing new amounts, key in the number of the current amount you want to store from and press [f][E]; this is necessary to update I-register (index control) contents. The index register contents is changed everytime a check is made (use of LBL C or LBL D). Also, when you a re about start over a new set, you can clear all registers contents with [f]CLEAR[REG] and you must key 1[f][E] to set the index register to the first register prior to use the sequence number[f][A].

After keying the program in, try this: (you may use FIX 4)

Key in            Display     Comments
[f]CLEAR[REG] 0.0000
1 [f][E] 1.0000 sets RI to 1.01
20 [f][A] 20.0000 stores 20 in R1
30 [f][A] 30.0000 stores 30 in R2
50 [f][A] 50.0000 stores 50 in R3
5 [f][B] running
5.0000 multiplies all values by factor (5)
[f][C] 1.0000 shown briefly
100.0000 R1 contents times factor
[R/S] 2.0000 shown briefly
150.0000 R2 contents times factor
[R/S] 3.0000 shown briefly
250.0000 R3 contents times factor
1 [f][D] 100.0000 R1 contents
3 [f][D] 250.0000 R3 contents
4 [f][E] 4.0000 gets ready do store values from R4

One last remark: the values stored after prior contents being updated are not updated automatically with this program. If you want, some small changes can be added so LBL A multiplies entered data by factor prior to store them. Or you may want values to be unchanged so they are only shown updated; what do you think? I guess keeping values entered through LBL A as they are keyed in allows bigger flexibility, but I was not sure if you wanted accumulated factors.

Let me know if this fits your needs or what changes you want to be made, O.K.?

Cheers.

Luiz (Brazil)

Listing

001-42,21,11 f LBL A
002- 44 24 STO (i)
003- 42 6 f ISG
004- 31 R/S
005-42,21,12 f LBL B
006- 44 0 STO 0
007- 1 1
008- 48 .
009- 0 0
010- 1 1
011- 44 25 STO I
012- 33 Rv (roll down)
013-42,21, 0 f LBL 0
014-44,20,24 STO × (i)
015- 42 6 f ISG
016- 22 0 GTO 0
017- 43 32 g RTN
018-42,21,13 f LBL C
019- 1 1
020- 48 .
021- 0 0
022- 1 1
023- 44 25 STO I
024-42,21, 1 f LBL 1
025- 45 25 RCL I
026- 43 44 g INT
027- 42 31 f PSE
028- 45 24 RCL (i)
029- 31 R/S
030- 42 6 f ISG
031- 22 1 GTO 1
032- 43 32 g RTN
033-42,21,14 f LBL D
034- 44 25 STO 25
035- 45 24 RCL (i)
036- 43 32 g RTN
037-42,21,15 f LBL E
038- 48 .
039- 0 0
040- 1 1
041- 40 +
042- 44 25 STO I
043- 43 44 g INT


Edited: 1 Sept 2004, 3:06 a.m. after one or more responses were posted


#11

Hi, Klaus;

this is the version that keeps values unchanged after setting a new factor. Each time you check registers contents they are multiplied by factor prior to be shown. And this is six steps shorter... Prior example works the same, but this time any new value stored after 4[f][E] will be shown multiplied by factor with [f][C] or n[F][D].

Cheers.

Listing

001-42,21,11 f LBL A
002- 44 24 STO (i)
003- 42 6 f ISG
004- 31 R/S
005-42,21,12 f LBL B
006- 44 0 STO 0
007- 43 32 g RTN
008-42,21,13 f LBL C
009- 1 1
010- 48 .
011- 0 0
012- 1 1
013- 44 25 STO I
014-42,21, 1 f LBL 1
015- 45 25 RCL I
016- 43 44 g INT
017- 42 31 f PSE
018- 45 24 RCL (i)
019- 45 0 RCL 0
020- 20 ×
021- 31 R/S
022- 42 6 f ISG
023- 22 1 GTO 1
024- 43 32 g RTN
025-42,21,14 f LBL D
026- 44 25 STO 25
027- 45 24 RCL (i)
028 45 0 RCL 0
029 20 ×
030- 43 32 g RTN
031-42,21,15 f LBL E
032- 48 .
033- 0 0
034- 1 1
035- 40 +
036- 44 25 STO I
037- 43 44 g INT


Edited: 1 Sept 2004, 2:04 a.m.


#12

Hi Luiz!

Thank you for your help, but it´s not exactly what I mean.
One possible solution may be:

initialize Register R0 to 0
Have a function named push storing the old value and the new value in 0.
Having a function pop getting the top of stack and storing the rest of stack in Register 0.

The user enters a 1 first.
the push function calculates push(0,1) where 0 is the stack
push(0,1) = 1
Then the user enters 5
push(1,5) = 26
Then the user enters 9
push(26,9) = 639
...

to po a number:
pop(639) = 9 and stack:=26
pop(26) = 5 and stack:=1
pop(1) = 1 and stack:=0

Has anyone done this before?


#13

Hi, Klaus;

I actually didn´t get some of your ideas and explanations. Can I try to clear them out?

Quote:
Have a function named push storing the old value and the new value in 0.
Each register inthe HP11C stores one value at a time. I cannot figure a way to store both the old value and the new value in the same register. BTW, what sort of values are the old and the new values?
Quote:
Having a function pop getting the top of stack and storing the rest of stack in Register 0.
When you mention top of stack do you mean the T-register or the top of another stack, simulated by the ten registers as you mentioned in your previous post? If the second option is the correct one, than you actually need one of both: a pointer to indicate the position of the last entered number (Index register) and this pointer must either be saved somewhere else when accessing data or never be touched except when pushing data in the "stack" (of numbered registers), like it actually happens in stack manipulations (processors). In any case, I cannot figure a way to store the whole stack contents in one single register...
Quote:
The user enters a 1 first. the push function calculates push(0,1) where 0 is the stack push(0,1) = 1 Then the user enters 5 push(1,5) = 26 Then the user enters 9 push(26,9) = 639 ...
I cannot understand from here, sorry! With push(1,5) = 26, what is the calculation performed?

I´m sad, I´d like to help.

Luiz (Brazil)


#14

Hi Luiz,

you said:
Each register inthe HP11C stores one value at a time. I cannot figure a way to store both the old value and the new value in the same register. BTW, what sort of values are the old and the new values?

And yoou are completely right, it´s all about storing the old and the new value in the same register. I have a solution for that, but with my solution I can only store 4 times a number between 0 and 99 in one register. (And only integers are allowed.)

I am curious if someone has another solution?
Klaus


#15

Hi, Klaus;

You mean something like this: given a number in the format

  aabbccddeeEnn
where:
  aabbccddee
is the mantissa, nn is the exponent of ten and each
  aa, bb, cc, dd, ee
is one of each possible (up to) five positive integers from 00 to 99, right? Is this what you want? KNowing another way to store all of them in R0? So your "stack" is the register contents itself, and you'd push and pop the positive integer from 00 to 99 into it? Or, if I got, you could also pick or put (fixed position) the number in there without disturbing the other values?

If so, I can also post a program for that. Just let me know.

Cheers.

Luiz (Brazil)

Edited: 1 Sept 2004, 2:49 p.m.


#16

Hi Luiz,

Thank you for your suggestions. The solution I search should not simply concatenate the numbers, but rather decode them as an integer. My solutioon is a formula implementing this table:
x->
0 2 5 9 ...
1 4 8 13
3 7 12 18
6 11 17 ...
...

Maybe there is another solution (perhaps using primes to decode the numbers. With my table, I use the x-value to lookup the row and the y-value to lookup the column.)

Thanks, Klaus


#17

Hi, Klaus;

now I'm curious. If I got it correctly, it is more interesting than I thought it should be. You want to decode numbers that were coded and added togheter. Is it correct? Please, what sort of method you are dealing with? Are you developing it or just trying to implement it in the HP11C?

If you want to go ahead, I'd be interested on knowing some more. if you want to and have the time, be my guest: lcvieira@quantica.com.br

Cheers.

Luiz (Brazil)


#18

Hi Luiz,

I have the math ready for push and pop, but I don´t have time to implement the routines on the 11c (it can only be useful when the routines take no registers and little program space). I will try to post the math today, if you are interested.


#19

Hi, Klaus;

I'd like to try to implement the routines, given the math, if you find the tme to post them. I'll try the smallest program and the least register number possible, O.K.?

Also, if there's anyone else interested on, I'd be gladly sharing RPN programming 'tips and tricks', if any.

Cheers.

Luiz (Brazil)


Edited: 2 Sept 2004, 8:53 p.m.


#20

Hi Luiz,
the math is as easy as 3.1415...:

Coding 2 Numbers:
c(x,y) = (((x+y+1)*(x+y))/2)+x

Decoding:

n = int((-0.5)+(0.25+(2*c))^(0.5))
x = c- (0.5*n*(n+1))
y = n -x

To push the numbers 3,5,7:

c(3,0) = 9
c(5,9) = 110
c(7,110)=6910

To pop a number, return x to the user and set the stack to y

Have fun! Klaus


#21

Hi, Klaus; (for the records: coincidentally my actual name is Luiz Claudio... )

First of all, folks, although this thread deals with programming and programming techniques, have you found it is too long and that it would be better keeping private e-mails, just add your comments. I guess Klaus should try having this answer for as long as he needs, but if you think that I should write him straight, I'd gladly do that/ Just let me know, O.K.?

About the expressions, the "coding 2 numbers" you wrote is:
c(x,y) = (((x+y+1)*(x+y))/2)+x

Based on your examples I "see" it like this:

cn(xn,cn-1) = (((xn+cn-1+1)*(xn+cn-1))/2)+xn | n=1,2,3..., C0=0

Would this be a better expression? Anyway, I wrote the following routine, that calculates cn given y and x in Y- and X-register respectively:

f LBL 0
+
g LSTx
x<>y (x xchange y)
ENTER
ENTER
1
+
×
2
÷
+
g RTN

Try:

0 [ENTER] 3 [GSB] 0  returns  9
5 [R/S] returns 110 (provided that the previous 9 is left in the display)
7 [R/S] returns 6910 (provided that the previous 110 is left in the display)

For decoding:

n = int((-0.5)+(0.25+(2*c))^(0.5))

x = c- (0.5*n*(n+1))

y = n -x

Given n in X-register, the following routine returns y and x in Y- and X-register respectively:

f LBL 1
ENTER
ENTER
ENTER
+
4
1/x
+
Vx (sqrt)
.
5
-
g INT
1
g LSTx
g INT
+
g LSTx
×
2
÷
+
g R^ (roll up)
-
CHS
-
g LSTx
g RTN

To decode the previous values:

110 [GSB] 1  returns 5.0000; press [x<>y to see 9.0000 
6910 [GSB] 1 returns 7.0000; press [x<>y] to see 110.0000
9 [GSB] 1 returns 3.0000; press [x<>y] to see 0.0000

Now I'm gonna find some time to go ahead with the accumulation. BTW, will "pop" remove the object from the "stack"? If so, is there (or should there be) a mechanism to avoid removing numbers that do not belong to the database? I guess that to accomplish such a verifying task it would be necessary to generate the whole chain for checking; am I wrong in this issue? Not the checking procedure, but in the fact that it would be a problem to try to remove a nonexistent value.

Let me know if the routines get closer to what you need, O.K.?

Cheers, Klaus. That's an intriguing problem...

Luiz (Brazil)


Edited: 3 Sept 2004, 5:32 p.m.


#22

Hi Luiz, thanks for your help! I could verify the results for the push, but the pop returns other results on my 11c (Perhaps I hit a wrong key- I need some time).
You suggest:
cn(xn,cn-1) = (((xn+cn-1+1)*(xn+cn-1))/2)+xn | n=1,2,3..., C0=0

I see it rather that way:
c(n0,n1,...,nk) = c(nk,c(nk-1,c(...,c(n0,0))...))

There is no need to do any checks on pop: each integer is a valid stack and can be popped many times (returning zero when the stack is empty).
BTW, for calculating x, you need 0.5n(n+1), which is the sum from i=0 to i=n of i.

Many thanks for your quick help on this problem, and I am sure one time I can use it in a program.

Greeting, Klaus


#23

Hi, Klaus;

You are correct. There is an extra [+] in my listing that is not in the original program (I have no idea why did I type it in...) Look at the following lisiting, please:

f LBL 1
ENTER
ENTER
ENTER
+
4
1/x
+
Vx (sqrt)
.
5
-
g INT
1
g LSTx
g INT
+
g LSTx
×
2
÷
+ <<<<<<<------- remove this [+]
g R^ (roll up)
-
CHS
-
g LSTx
g RTN

It seems to me it is gonna work fine, now. Hope it helps. BTW, the expression you post for cn is great! Thanks!

Best regards.

Luiz (Brazil)


#24

Hi Luiz!

You say:

BTW, the expression you post for cn is great! Thanks!


I think, I posted it the wrong way. I think it has to be:

c(n0,n1,...,nk) = c(c(c(...c(n0,0),n1),...),n1),n0)

(depends on the way one chooses to implement it)

Thank you very much and best wishes! Klaus

#25

Hi Luix, i sent you a email; did you receive it?


1234


Possibly Related Threads...
Thread Author Replies Views Last Post
  Reasonable price for a 41C, Quad Mem, Time, Navigation and Card reader module? Eelco Rouw 10 2,678 12-12-2013, 01:52 AM
Last Post: Eelco Rouw
  Converting Great Circle Navigation from 41C to 42S Bill Triplett 11 2,078 11-13-2013, 07:24 AM
Last Post: Kimberly Thompson
  HP Prime: Converting number to Sci notation and back BruceTTT 1 758 11-12-2013, 02:11 AM
Last Post: Phil Wipf
  HP Prime: run a program in another program Davi Ribeiro de Oliveira 6 1,461 11-11-2013, 08:28 PM
Last Post: Davi Ribeiro de Oliveira
  Little curiosity: why the fourth stack register is called "T"? Antlab 34 4,783 07-03-2013, 04:49 PM
Last Post: Walter B
  [wp34s] Converting to/from IEEE 754 Binary64 (Double Precision) David Maier 1 664 06-15-2013, 09:21 PM
Last Post: Paul Dale
  OT - Converting 9 track 6250 bpi tapes Marcel Samek 0 494 05-31-2013, 08:26 PM
Last Post: Marcel Samek
  [WP34S] Register use by functions. Chris Tvergard 5 1,184 05-12-2012, 03:35 AM
Last Post: Walter B
  HP-34C Storage Register Arithmetic & Programming Matt Agajanian 14 2,142 05-08-2012, 11:04 AM
Last Post: Matt Agajanian
  Sleek approach to Register Exchange on HP-29C Matt Agajanian 8 1,583 03-16-2012, 01:04 PM
Last Post: Marcus von Cube, Germany

Forum Jump: