{"id":2353,"date":"2019-08-03T00:17:17","date_gmt":"2019-08-03T00:17:17","guid":{"rendered":"http:\/\/www.sydneysmith.com\/wordpress\/?p=2353"},"modified":"2019-08-03T00:17:17","modified_gmt":"2019-08-03T00:17:17","slug":"hp-25-input-mode","status":"publish","type":"post","link":"https:\/\/www.sydneysmith.com\/wordpress\/2353\/hp-25-input-mode\/","title":{"rendered":"HP-25 Input Mode"},"content":{"rendered":"<p>Here&#8217;s what happens as you key in digits into the calculator. <!--more--><\/p>\n<h2>First Digit<\/h2>\n<p>1. The first thing that happens is the digit key gets converted to a program code (prgcode). This is the internal value that would get stored in program memory as a program step if we were pressing the key in PRGM mode. Here&#8217;s the process:<br \/>\n<code><\/p>\n<pre>\r\nKeyPressed:\r\n00762 display off\r\n00763 binary\r\n00764 p <- 0\r\n00765 0 -> c[x]\r\n00766 a exchange b[w]                    ; A= 21000000000000 B= 0000ffffffffff\r\n00767 0 -> s 13\r\n00770 keys -> rom address\r\n\r\n; 0162 = 01 110 010 = 0111 0010 = 72H = [1] key pressed\r\n00562 if n\/c goto 00647\r\n00647 c + 1 -> c[x]                      ; C= 00000000000001\r\n00650 return\r\n\r\n00674 p <- 1                             ; P= 1\r\n00675 load constant 12                   ; C= 000000000000c1 P= 0\r\n00676 p <- 1                             ; P= 1\r\n<\/pre>\n<p><\/code><br \/>\nC[1,0] now contains \"c1\", the prgcode for the [1] key.<\/p>\n<p>2. The calculator then checks for prefix keys (in case [f], [g] or [STO] had been pressed):<br \/>\n<code><\/p>\n<pre>\r\n00677 if 1 = s 10 then goto 00704        ; if g_pressed, no\r\n00701 if 0 = s 9 then goto 00616         ; if not f_pressed, yes\r\n00616 delayed rom 3\r\n00617 if n\/c goto 00526\r\n01526 if 1 = s 3 then goto 01766         ; if RUN\r\n<\/pre>\n<p><\/code><\/p>\n<p>3. It then runs the prgcode, exactly as if it had come from program memory:<br \/>\n<code><\/p>\n<pre>\r\nexecut:\r\n01766 0 -> c[xs]\r\n01767 c -> a[x]                          ; A= 210000000000c1\r\n01770 a + 1 -> a[xs]                     ; A= 210000000001c1\r\n01771 a -> rom address\r\n<\/pre>\n<p><\/code><\/p>\n<p>4. Every digit key (0-9), and each of the undocumented \"a\"-\"f\" ones, ends up at the same place:<br \/>\n<code><\/p>\n<pre> \r\n; 1c\r\n01434 select rom 0\r\n00035 if 1 = s 7 then goto 00076         ; if EEX, no\r\n00037 jsb 00356\r\n\r\npush:\r\n00356 if 1 = s 8 then goto 00376         ; if input_mode, not yet\r\n00360 0 -> c[w]                          ; C= 00000000000000\r\n00361 m2 exch c\r\n00362 if 0 = s 2 then goto 00365         ; if not auto_enter, true\r\n00365 1 -> s 2                           ; S= ..23.5.........f auto_enter\r\n00366 0 -> c[w]\r\n00367 binary\r\n00370 c - 1 -> c[w]                      ; C= ffffffffffffff CY\r\n00371 f exch a                           ; A= 210000000001c0 (f=1)\r\n00372 0 -> a[w]                          ; A= 00000000000000\r\n00373 f exch a                           ; A= 00000000000001\r\n00374 0 -> c[s]                          ; C= 0fffffffffffff\r\n00375 b exchange c[w]                    ; B= 0fffffffffffff C= 0000ffffffffff\r\n00376 1 -> s 8                           ; S= ..23.5..8......f input_mode\r\n00377 return\r\n<\/pre>\n<p><\/code><br \/>\nIf this is the first digit (HP labelled s8 as \"firdig\"), the new X value gets set to 0, the old X value gets \"push\"ed up the stack (00364 is c -&gt; stack) and B is set to a positive sign \"0\" then 13 \"f\"s. Our \"1\" digit is also in A[0].<\/p>\n<p>The s2 flag is called \"push\" by HP. I refer to it as \"auto_enter\" for historic reasons. Both mean the same thing: it is clear after a CLx or an ENTER, and set otherwise. It is the flag that causes a new value to push the existing values up the stack (Z to T, Y to Z, X to Y).<\/p>\n<p>5. Next, the digit in A[0] is shifted left for as many positions as there are \"f\"s. The \"f\"s display as blanks so this is effectively putting the digit in the next available spot. (This is also why trying to put an \"f\" digit in a spot results in the \"f\" digit getting overwritten by the next digit - see HP-25 Non Normalized Numbers). The process look like this:<br \/>\n<code><\/p>\n<pre>\r\n00040 b -> c[w]                          ; C= 0fffffffffffff\r\n00041 p <- 1\r\n;\r\n00042 c + 1 -> c[p]                      ; C= 0fffffffffff0f CY\r\n00043 if n\/c goto 00332\r\n00044 shift left a[w]                    ; A= 00000000000010\r\n00045 p + 1 -> p                         ; P= 2\r\n00046 if p # 13 then goto 00042\r\n;\r\n00042 ...                                ; C= 0ffffffffff00f A= 00000000000100 P= 3\r\n00042 ...                                ; C= 0fffffffff000f A= 00000000001000 P= 4\r\n00042 ...                                ; C= 0ffffffff0000f A= 00000000010000 P= 5\r\n00042 ...                                ; C= 0fffffff00000f A= 00000000100000 P= 6\r\n00042 ...                                ; C= 0ffffff000000f A= 00000001000000 P= 7\r\n00042 ...                                ; C= 0fffff0000000f A= 00000010000000 P= 8\r\n00042 ...                                ; C= 0ffff00000000f A= 00000100000000 P= 9\r\n00042 ...                                ; C= 0fff000000000f A= 00001000000000 P=10\r\n00042 ...                                ; C= 0ff0000000000f A= 00010000000000 P=11\r\n00042 ...                                ; C= 0f00000000000f A= 00100000000000 P=12\r\n00042 ...                                ; C= 0000000000000f A= 01000000000000 P=13\r\n00046 if p # 13 then goto 00042\r\n00050 p - 1 -> p                         ; P= 12\r\n00051 a exchange c[wp]                   ; A= 0000000000000f C= 01000000000000\r\n00052 p - 1 -> p                         ; P= 11\r\n00053 c -> a[w]                          ; A= 01000000000000\r\n<\/pre>\n<p><\/code><\/p>\n<p>6. It puts the \"f\"s back on the RHS of our shifted digit:<br \/>\n<code><\/p>\n<pre>\r\n00054 c - 1 -> c[wp]                     ; C= 01ffffffffffff CY\r\n<\/pre>\n<p><\/code><\/p>\n<p>7. There is some work with the exponent which makes more sense on subsequent digits:<br \/>\n<code><\/p>\n<pre>\r\n00055 a exchange c[x]                    ; A= 01000000000fff C= 01fffffffff000\r\n00056 decimal\r\n00057 if a[m] # 0 then goto 00006\r\n00006 jsb 00133\r\n\r\ndelook:\r\n00133 a exchange b[x]\r\n00134 0 -> a[x]                          ; A= 01000000000000\r\n00135 f -> a\r\n00136 a + c -> c[x]\r\n00137 p <- 12                            ; P= 12\r\n00140 if c[p] # 0 then goto 00353\r\n00353 a exchange b[x]                    ; A= 01000000000fff B= 0ffffffffff000\r\n00354 0 -> b[x]\r\n00355 return\r\n<\/pre>\n<p><\/code><\/p>\n<p>8. The keyed in digit(s) (X value) gets stored in M2<br \/>\n<code><\/p>\n<pre>\r\n00007 if n\/c goto 00062\r\n00062 a exchange c[ms]                   ; A= 01ffffffffffff C= 01000000000000\r\n00063 m2 exch c                          ; C= 00000000000000 M2=01000000000000\r\n00064 a exchange b[w]                    ; A= 0ffffffffff000 B= 01ffffffffffff\r\n<\/pre>\n<p><\/code><\/p>\n<p>9. Then we put \"21\" in B to turn on the sign and show a decimal point, and then show the digit(s):<br \/>\n<code><\/p>\n<pre>\r\n00065 jsb 00341\r\n\r\ndeb: ; digit entry, set B\r\n; this mostly puts \"21\" in B to show sign and decimal point\r\n; the entered digits are currently in B and will end up in A\r\n00341 0 -> a[w]                          ; A= 00000000000000\r\n00342 a + 1 -> a[s]                      ; A= 10000000000000\r\n00343 shift right a[w]                   ; A= 01000000000000\r\n00344 a + 1 -> a[s]                      ; A= 11000000000000\r\n00345 a + 1 -> a[s]                      ; A= 21000000000000\r\n00346 a exchange b[ms]                   ; A= 01fffffffff000 B= 21000000000fff\r\n00347 f -> a\r\n00350 p <- 0                             ; P= 0\r\n00351 a - 1 -> a[p]                      ; A= 01fffffffff009 CY\r\n00352 if n\/c goto 00233\r\n00353 a exchange b[x]                    ; A= 01ffffffffffff B= 21000000000009\r\n00354 0 -> b[x]                          ; B= 21000000000000\r\n00355 return\r\n\r\n00066 a exchange b[w]                    ; A= 21000000000000 B= 01ffffffffffff\r\n00067 if 1 = s 1 then goto 01754         ; if running, no\r\n00071 a exchange b[w]                    ; A= 01ffffffffffff B= 21000000000000\r\n00072 if 0 = s 3 then goto 01672         ; if PRGM, no\r\n00074 delayed rom 1\r\n00075 if n\/c goto 00165\r\n\r\n$plain:\r\n00565 0 -> s 9                           ; f_pressed= no\r\n00566 0 -> s 10                          ; g_pressed= no\r\n00567 if n\/c goto 00672\r\n00672 0 -> s 14                          ; sto_prefix= no\r\n00673 jsb 00751\r\n\r\n00751 display toggle                     ; \" 1.\"\r\n<\/pre>\n<p><\/code><br \/>\nAfter this, we wait for any pressed key to be released and go into the WaitLoop for the next key press.<\/p>\n<h2>Second Digit<\/h2>\n<p>10. I'll skip over some of the detail above, but here's what happens when you now press [2]:<br \/>\n<code><\/p>\n<pre>\r\nKeyPressed:\r\n00762 ...\r\n00770 keys -> rom address\r\n...\r\n00675 ...                                ; C= 000000000000c2 (c2= prgcode for [2])\r\n\r\nexecut:\r\n01766 ...                                ; A= 210000000001c2\r\n01771 a -> rom address\r\n\r\n; 1c\r\n01434 select rom 0\r\n00035 if 1 = s 7 then goto 00076\r\n00037 jsb 00356\r\n\r\n00356 if 1 = s 8 then goto 00376\r\n00376 1 -> s 8\r\n00377 return\r\n\r\n00040 b -> c[w]                          ; C= 01ffffffffffff\r\n00041 p <- 1\r\n00042 ...                                ; C= 01ffffffffff0f A= 10000000001c20 P= 2\r\n00042 ...                                ; C= 01fffffffff00f A= 0000000001c200 P= 3\r\n00042 ...                                ; C= 01ffffffff000f A= 000000001c2000 P= 4\r\n00042 ...                                ; C= 01fffffff0000f A= 00000001c20000 P= 5\r\n00042 ...                                ; C= 01ffffff00000f A= 0000001c200000 P= 6\r\n00042 ...                                ; C= 01fffff000000f A= 000001c2000000 P= 7\r\n00042 ...                                ; C= 01ffff0000000f A= 00001c20000000 P= 8\r\n00042 ...                                ; C= 01fff00000000f A= 0001c200000000 P= 9\r\n00042 ...                                ; C= 01ff000000000f A= 001c2000000000 P=10\r\n00042 ...                                ; C= 01f0000000000f A= 01c20000000000 P=11\r\n00042 ...                                ; C= 0100000000000f A= 1c200000000000 P=12\r\n00042 c + 1 -> c[p]                      ; C= 0200000000000f\r\n00043 if n\/c goto 00332\r\n00332 c - 1 -> c[p]                      ; C= 0100000000000f\r\n00333 if p # 3 then goto 00171\r\n00171 if 1 = s 6 then goto 00050         ; if dp (decimal point), no\r\n00173 f exch a                           ; f=0 from last time (0th digit)\r\n00174 a + 1 -> a[x]                      ; A= 1c200000000001\r\n00175 f exch a                           ; A= 1c200000000000, f now 1\r\n00176 if n\/c goto 00050\r\n00050 p - 1 -> p                         ; P= 11\r\n00051 a exchange c[wp]                   ; A= 1c00000000000f C= 01200000000000\r\n00052 p - 1 -> p                         ; P= 10\r\n00053 c -> a[w]                          ; A= 01200000000000\r\n00054 c - 1 -> c[wp]                     ; C= 012fffffffffff CY\r\n00055 a exchange c[x]                    ; A= 01200000000fff C= 012ffffffff000\r\n00056 decimal\r\n00057 if a[m] # 0 then goto 00006\r\n00006 jsb 00133\r\n\r\n00133 a exchange b[x]\r\n00134 0 -> a[x]                          ; A= 01200000000000\r\n00135 f -> a                             ; A= 01200000000001\r\n00136 a + c -> c[x]                      ; C= 012ffffffff001\r\n00137 p <- 12                            ; P= 12\r\n00140 if c[p] # 0 then goto 00353\r\n00353 a exchange b[x]                    ; A= 01200000000fff B= 01fffffffff001\r\n00354 0 -> b[x]                          ; B= 01fffffffff000\r\n00355 return\r\n\r\n00007 if n\/c goto 00062\r\n00062 a exchange c[ms]                   ; A= 012fffffffffff C= 01200000000001\r\n00063 m2 exch c                          ; C= 01000000000000 M2=01200000000001\r\n00064 a exchange b[w]                    ; A= 01fffffffff000 B= 012fffffffffff\r\n00065 jsb 00341\r\n\r\ndeb: ; digit entry, set B\r\n; this time B=201 for sign, 2 digits, decimal point\r\n00341 0 -> a[w]                          ; A= 00000000000000\r\n00342 a + 1 -> a[s]                      ; A= 10000000000000\r\n00343 shift right a[w]                   ; A= 01000000000000\r\n00344 a + 1 -> a[s]                      ; A= 11000000000000\r\n00345 a + 1 -> a[s]                      ; A= 21000000000000\r\n00346 a exchange b[ms]                   ; A= 012ffffffff000 B= 21000000000fff\r\n00347 f -> a                             ; A= 012ffffffff001\r\n00350 p <- 0                             ; P= 0\r\n00351 a - 1 -> a[p]                      ; A= 012ffffffff000\r\n00352 if n\/c goto 00233\r\n00233 shift right b[m]                   ; B= 20100000000fff\r\n00234 if n\/c goto 00351\r\n00351 a - 1 -> a[p]                      ; A= 012ffffffff009 CY\r\n00352 if n\/c goto 00233\r\n00353 a exchange b[x]                    ; A= 012fffffffffff B= 20100000000009\r\n00354 0 -> b[x]                          ; B= 20100000000000\r\n00355 return\r\n\r\n00066 ...\r\n\r\n$plain:\r\n00565 ...\r\n\r\n00751 display toggle                     ; \" 12.\"\r\n<\/pre>\n<p><\/code><\/p>\n<h2>Third Digit<\/h2>\n<p>11. The process repeats for further digits. Here's a third one so the pattern is clear:<br \/>\n<code><\/p>\n<pre>\r\nKeyPressed:\r\n00762 ...\r\n00770 keys -> rom address\r\n\r\nkey_3:\r\n00560 ...                                ; C= 010000000000c3 (c3= prgcode for [3])\r\n\r\nexecut:\r\n01766 ...                                ; A= 201000000001c3\r\n01771 a -> rom address\r\n\r\n01434 ...\r\n00037 jsb 00356\r\n\r\n00356 if 1 = s 8 then goto 00376         ; already input mode\r\n00376 1 -> s 8                           ; nothing to do here\r\n00377 return\r\n\r\n00040 b -> c[w]                          ; C= 012fffffffffff\r\n00041 p <- 1\r\n00042 ...                                ; C= 012fffffffff0f A= 01000000001c30 P= 2\r\n00042 ...                                ; C= 012ffffffff00f A= 1000000001c300 P= 3\r\n00042 ...                                ; C= 012fffffff000f A= 000000001c3000 P= 4\r\n00042 ...                                ; C= 012ffffff0000f A= 00000001c30000 P= 5\r\n00042 ...                                ; C= 012fffff00000f A= 0000001c300000 P= 6\r\n00042 ...                                ; C= 012ffff000000f A= 000001c3000000 P= 7\r\n00042 ...                                ; C= 012fff0000000f A= 00001c30000000 P= 8\r\n00042 ...                                ; C= 012ff00000000f A= 0001c300000000 P= 9\r\n00042 ...                                ; C= 012f000000000f A= 001c3000000000 P=10\r\n00042 ...                                ; C= 0120000000000f A= 01c30000000000 P=11\r\n00042 c + 1 -> c[p]                      ; C= 0130000000000f\r\n00043 if n\/c goto 00332\r\n00332 c - 1 -> c[p]                      ; C= 0120000000000f (3 back to 2)\r\n00333 if p # 3 then goto 00171\r\n00171 if 1 = s 6 then goto 00050\r\n00173 f exch a                           ; A= 01c30000000001\r\n00174 a + 1 -> a[x]                      ; A= 01c30000000002\r\n00175 f exch a                           ; A= 01c30000000000\r\n00176 if n\/c goto 00050\r\n00050 p - 1 -> p                         ; P= 10\r\n00051 a exchange c[wp]                   ; A= 01c0000000000f C= 01230000000000\r\n00052 p - 1 -> p                         ; P= 9\r\n00053 c -> a[w]                          ; A= 01230000000000\r\n00054 c - 1 -> c[wp]                     ; C= 0123ffffffffff CY\r\n00055 a exchange c[x]                    ; A= 01230000000fff C= 0123fffffff000\r\n00056 decimal\r\n00057 if a[m] # 0 then goto 00006\r\n00006 jsb 00133\r\n\r\n00133 a exchange b[x]\r\n00134 0 -> a[x]                          ; A= 01230000000000\r\n00135 f -> a                             ; A= 01230000000002\r\n00136 a + c -> c[x]                      ; C= 0123fffffff002\r\n00137 p <- 12                            ; P= 12\r\n00140 if c[p] # 0 then goto 00353\r\n00353 a exchange b[x]                    ; A= 01230000000fff B= 012ffffffff002\r\n00354 0 -> b[x]                          ; B= 012ffffffff000\r\n00355 return\r\n\r\n00007 if n\/c goto 00062\r\n00062 a exchange c[ms]                   ; A= 0123ffffffffff C= 01230000000002\r\n00063 m2 exch c                          ; C= 01200000000001 M2=01230000000002\r\n00064 a exchange b[w]                    ; A= 012ffffffff000 B= 0123ffffffffff\r\n00065 jsb 00341\r\n\r\ndeb: ; digit entry, set B\r\n; B = \"2001\" ie sign, 3 x digit, decimal point\r\n00341 0 -> a[w]                          ; A= 00000000000000\r\n00342 a + 1 -> a[s]                      ; A= 10000000000000\r\n00343 shift right a[w]                   ; A= 01000000000000\r\n00344 a + 1 -> a[s]                      ; A= 11000000000000\r\n00345 a + 1 -> a[s]                      ; A= 21000000000000\r\n00346 a exchange b[ms]                   ; A= 0123fffffff000 B= 21000000000fff\r\n00347 f -> a                             ; A= 0123fffffff002\r\n00350 p <- 0                             ; P= 0\r\n00351 a - 1 -> a[p]                      ; A= 0123fffffff001\r\n00352 if n\/c goto 00233\r\n00233 shift right b[m]                   ; B= 20100000000fff\r\n00234 if n\/c goto 00351\r\n00351 a - 1 -> a[p]                      ; A= 0123fffffff000\r\n00352 if n\/c goto 00233\r\n00233 shift right b[m]                   ; B= 20010000000fff\r\n00234 if n\/c goto 00351\r\n00351 a - 1 -> a[p]                      ; A= 0123fffffff009 CY\r\n00352 if n\/c goto 00233\r\n00353 a exchange b[x]                    ; A= 0123ffffffffff B= 20010000000009\r\n00354 0 -> b[x]                          ; B= 20010000000000\r\n00355 return\r\n\r\n00066 ...\r\n\r\n$plain:\r\n00565 ...\r\n\r\n00751 display toggle                     ; \" 123.\"\r\n<\/pre>\n<p><\/code><br \/>\nAs you can see, each time we add a digit (and the decimal point shifts one place to the right), the value in f goes up by one and the exponent in M2 goes up by one.<\/p>\n<table>\n<tr>\n<td>Digit<\/td>\n<td>f<\/td>\n<td>M2<\/td>\n<\/tr>\n<tr>\n<td>First<\/td>\n<td>0 to 1<\/td>\n<td>01000000000000<\/td>\n<\/tr>\n<tr>\n<td>Second<\/td>\n<td>1 to 2<\/td>\n<td>01200000000001<\/td>\n<\/tr>\n<tr>\n<td>Third<\/td>\n<td>2 to 3<\/td>\n<td>01230000000002<\/td>\n<\/tr>\n<\/table>\n<p>This is part of the <a href=\"http:\/\/www.sydneysmith.com\/wordpress\/hp25-main\/\">HP-25 topic<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Here&#8217;s what happens as you key in digits into the calculator.<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[16,5,69],"tags":[],"_links":{"self":[{"href":"https:\/\/www.sydneysmith.com\/wordpress\/wp-json\/wp\/v2\/posts\/2353"}],"collection":[{"href":"https:\/\/www.sydneysmith.com\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.sydneysmith.com\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.sydneysmith.com\/wordpress\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.sydneysmith.com\/wordpress\/wp-json\/wp\/v2\/comments?post=2353"}],"version-history":[{"count":2,"href":"https:\/\/www.sydneysmith.com\/wordpress\/wp-json\/wp\/v2\/posts\/2353\/revisions"}],"predecessor-version":[{"id":2355,"href":"https:\/\/www.sydneysmith.com\/wordpress\/wp-json\/wp\/v2\/posts\/2353\/revisions\/2355"}],"wp:attachment":[{"href":"https:\/\/www.sydneysmith.com\/wordpress\/wp-json\/wp\/v2\/media?parent=2353"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.sydneysmith.com\/wordpress\/wp-json\/wp\/v2\/categories?post=2353"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.sydneysmith.com\/wordpress\/wp-json\/wp\/v2\/tags?post=2353"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}