{"id":1489,"date":"2016-01-03T13:21:40","date_gmt":"2016-01-03T13:21:40","guid":{"rendered":"http:\/\/www.sydneysmith.com\/wordpress\/?p=1489"},"modified":"2017-05-14T00:41:02","modified_gmt":"2017-05-14T00:41:02","slug":"hp-65-number-entry-microcode","status":"publish","type":"post","link":"https:\/\/www.sydneysmith.com\/wordpress\/1489\/hp-65-number-entry-microcode\/","title":{"rendered":"HP-65 Number Entry Microcode"},"content":{"rendered":"<p>Here&#8217;s what happens when you press 123.45 EEX 78 CHS. <!--more--><\/p>\n<p>The numbers (0-9) end up in A[0]. <\/p>\n<pre>\r\nA[0] starts with 0 because of:\r\n00701 shiftl a[w]        ; A= 00000000009990\r\n\r\npressing the 0-9 keys give:\r\nkey scan  addr  instr\r\n[0] (044) 01044\trom 5 ;-&gt; 02445\r\n[1] (004) 01004\trom 5 ;-&gt; 02405\r\n[2] (003) 01003\trom 5 ;-&gt; 02404\r\n[3] (002) 01002\trom 5 ;-&gt; 02403\r\n[4] (024) 01024\trom 5 ;-&gt; 02425\r\n[5] (023) 01023\trom 5 ;-&gt; 02424\r\n[6] (022) 01022\trom 5 ;-&gt; 02423\r\n[7] (064) 01064\trom 5 ;-&gt; 02465\r\n[8] (063) 01063\trom 5 ;-&gt; 02464\r\n[9] (062) 01062\trom 5 ;-&gt; 02463\r\n\r\nwhich leads to:\r\nd9: 02463 a + 1 -&gt; a[x]\r\nd8: 02464 a + 1 -&gt; a[x]\r\nd7: 02465 ... : a + 1 -&gt; a[x]\r\nd6: 02423 a + 1 -&gt; a[x]\r\nd5: 02424 a + 1 -&gt; a[x]\r\nd4: 02425 ... : a + 1 -&gt; a[x]\r\nd3: 02403 a + 1 -&gt; a[x]\r\nd2: 02404 a + 1 -&gt; a[x]\r\nd1: 02405 ... :\ta + 1 -&gt; a[x]\r\nd0: 02445 goto 02506\r\n\r\nso A[0] ends with 0-9 to match the pressed key.<\/pre>\n<p>What happens next with the digits is: <\/p>\n<pre>\r\n02506 if c[m] = 0        ; if no prefix(es)\r\n02507 goto 02736\r\n; put C and M back \r\n02736 c &lt;-&gt; m            ; C= 00000000000000 M= 00000000000221\r\n02737 if s3 = 0          ; if in RUN mode\r\n02740 goto 02511\r\n02511 rom 2\r\n01112 if s1 = 0          ; if not input_started\r\n01113 goto 01245\r\n\r\n;if the auto_enter flag is set\r\n;  c -&gt; stack\r\n;endif\r\n;clear auto_enter flag\r\n;\r\n01245 0 -&gt; s11\r\n01246 0 -&gt; f1            ; clear auto_enter flag\r\n01247 if s11 = 0         ; if f1 wasn't set\r\n01250 goto 01252\r\n01251 c -&gt; stack\r\n\r\n; set B for \"\".\r\n01252 0 -&gt; c[w]\r\n01253 12 -&gt; p\r\n01254 c - 1 -&gt; c[wp]     ; C= 09999999999999\r\n01255 c + 1 -&gt; c[s]      ; C= 19999999999999\r\n01256 c + 1 -&gt; c[s]      ; C= 29999999999999\r\n01257 b &lt;-&gt; c[w]         ; B= 29999999999999 C= 02009999999999\r\n; set C=0\r\n01260 0 -&gt; c[w]          ; C= 00000000000000\r\n\r\n; if . not yet pressed\r\n;   move decimal point another place to the right\r\n; endif\r\n01261 if s2 = 0          ; if not dot_pressed\r\n01262 goto 01127\r\n01263 goto 01130\r\n01127 shiftr b[w]        ; B= 02999999999999\r\n\r\n; \/\/ put A[0] digit in next available position\r\n; \/\/ (the next available position is determined from the mask normally in B)\r\n; for (p=0; C[p]==0; p++)\r\n;   shift digit in A[0] left\r\n01130 b &lt;-&gt; c[w]         ; B= 00000000000000 C= 02999999999999\r\n01131 c + 1 -&gt; c[w]      ; C= 03000000000000\r\n01132 0 -&gt; p             ; P= 0\r\n01133 if c[p] &gt;= 1\r\n01134 goto 01151\r\n01135 p + 1 -&gt; p         ; P= 1\r\n01136 shiftl a[wp]       ; A= 00000000009910\r\n01137 goto 01133\r\n; P= 2 A= 00000000009100\r\n; P= 3 A= 00000000001000\r\n; P= 4 A= 00000000010000\r\n; P= 5 A= 00000000100000\r\n; P= 6 A= 00000001000000\r\n; P= 7 A= 00000010000000\r\n; P= 8 A= 00000100000000\r\n; P= 9 A= 00001000000000\r\n; P=10 A= 00010000000000\r\n; P=11 A= 00100000000000\r\n; P=12 A= 01000000000000\r\n01137 goto 01133\r\n01133 if c[p] &gt;= 1\r\n01134 goto 01151\r\n\r\n; restore mask\r\n01151 c - 1 -&gt; c[w]      ; C= 02999999999999\r\n01152 b &lt;-&gt; c[w]         ; B= 02999999999999 C= 00000000000000 <\/pre>\n<p>We now have the digit(s) in the A register and the mask (B register) set. Next is: <\/p>\n<pre>\r\n; if just started data entry (this is digit 1)\r\n01153 if p # 3\r\n01154 goto 01366\r\n01366 if s1 = 0\r\n01367 goto 01361\r\n; then\r\n01361 shiftl a[w]        ; A= 10000000000000\r\n01362 1 -&gt; s1            ; S= .1.......... (input_started)\r\n01363 goto 01156\r\n01156 shiftr a[ms]       ; A= 01000000000000\r\n01157 c -&gt; a[s]\r\n01160 if s7 = 0          ; no EEX yet\r\n01161 goto 01163\r\n01163 1 -&gt; s9            ; S= .1.......9.. (display_input)\r\n01164 0 -&gt; f3            ; S= .1.......9.b f= ..2..5.. (not display_x)\r\n01165 1 -&gt; f1            ; f= .12..5.. (set auto_enter)\r\n01166 rom 1\r\n00567 a &lt;-&gt; c[w]         ; A= 00000000000000 C= 01000000000000\r\n00570 c -&gt; a[w]          ; A= 01000000000000\r\n00571 if a[m] &gt;= 1       ; often if a[m]=0 then a[w]=0 (ie set exp 0 too)\r\n00572 goto 00546\r\n00546 c + 1 -&gt; c[xs]     ; C= 01000000000100 (actually test xs. if 9 dont goto)\r\n00547 goto 00470\r\n00470 0 -&gt; c[xs]         ; C= 01000000000000\r\n00471 13 -&gt; p            ; P= 13\r\n00472 c - 1 -&gt; c[x]      ; C= 01000000000999\r\n00473 if b[p] = 0\r\n00474 goto 00463\r\n00463 p - 1 -&gt; p         ; P= 12\r\n00464 c + 1 -&gt; c[x]      ; C= 01000000000000\r\n00465 jsb 00473\r\n00473 if b[p] = 0\r\n00474 goto 00463\r\n00475 12 -&gt; p\r\n00476 if a[p] &gt;= 1\r\n00477 goto 00574\r\n00574 a &lt;-&gt; c[m]\r\n00575 rom 2\r\n01176 if c[xs] = 0\r\n01177 goto 01334\r\n01334 if c[m] &gt;= 1\r\n01335 goto 01337\r\n01337 if p # 14\r\n01340 goto 01217\r\n01217 rom 1\r\n00620 if s8 = 0\r\n00621 goto 00531 <\/pre>\n<p>The input_started flag has been set.<\/p>\n<p>We have also set the display_input flag instead of the more usual display_x flag.<\/p>\n<p>The C register (stack X) contains the actual value (1e0) in case we decide to use it as currently keyed in (ie press a operation key).<\/p>\n<p>If we key in additional digits, input_started is set so we don&#8217;t initialize values like we just did. A slightly different path gets followed: <\/p>\n<pre>\r\n; elseif this is digit 2+ (but pre . pre EEX)\r\n; A= 12000000000000 B= 02999999999999 C= 01000000000000\r\n01153 if p # 3\r\n01154 goto 01366\r\n01366 if s1 = 0          ; if not input_started\r\n01367 goto 01361\r\n; then\r\n01370 if s2 = 0          ; if not dot_pressed\r\n01371 goto 01107\r\n01107 shiftr b[wp]       ; B= 00299999999999\r\n01110 jsb 01156\r\n01156 ...\r\n(as above)\r\n; S= .1.......9.b f= .12..5..\r\n; A= 01200000000000 C= 01200000000001 P= 12\r\n00621 goto 00531 <\/pre>\n<p>Pressing dot changes subsequent behaviour. It no longer pushes the decimal point to the right with each digit entered: <\/p>\n<pre>\r\n; press [.]\r\n; key scan  addr  instr\r\n; [.] (043) 01043 goto 01271\r\n;\r\n; which leads to:\r\n01271 if c[m] &gt;= 1       ; if prefix(es)\r\n01272 goto 01270\r\n01273 1 -&gt; s2            ; S= .12......... (dot_pressed)\r\n01274 if s1 = 0          ; if not input_started\r\n01275 goto 01044\r\n01276 goto 01304         ; but it has\r\n01304 c &lt;-&gt; m            ; C= 01230000000002 M= 00000000000221\r\n01305 shiftr a[w]        ; A= 01230000000000\r\n01306 jsb 01157          ; never returns?\r\n01157 ...\r\n(as above but more looping and s2 set)\r\n; S= .12......9.b f= .12..5..\r\n; A= 01230000000000 C= 01230000000000\r\n; P= 13 C= 01230000000999\r\n; P= 12 C= 01230000000000\r\n; P= 11 C= 01230000000001\r\n; P= 10 C= 01230000000002 (C= 1.23e2 ie \"123.\")\r\n; P= 12\r\n00621 goto 00531\r\n\r\n; press [4]\r\n;\r\n; which leads to:\r\n; P=10 A= 12340000000000 B= 00029999999999 C= 01230000000002\r\n\r\n; if this is digit 2+ (but after . pre EEX)\r\n01153 if p # 3\r\n01154 goto 01366\r\n01366 if s1 = 0          ; if not input_started (not digit 1)\r\n01367 goto 01361\r\n01370 if s2 = 0          ; if not dot_pressed\r\n01371 goto 01107\r\n; then\r\n01372 p - 1 -&gt; p         ; P= 9\r\n01373 0 -&gt; b[p]          ; B= 00020999999999\r\n01374 jsb 01156\r\n01156 ...\r\n(as above)\r\n; S= .12......9.b f= .12..5..\r\n; A= 01234000000000 C= 01234000000002 P= 12\r\n00621 goto 00531<\/pre>\n<p>The dot_pressed (s2) flag is set.<\/p>\n<p>You can see the mask in B now has a &#8220;hole&#8221; (0) to the right of the decimal point digit (2). This lets the &#8220;4&#8221; show through on the display. We see &#8221; 123.4&#8243; because A contains &#8220;01234&#8221; and B contains &#8220;00020999999999&#8221;.<\/p>\n<p>More digits add more holes (0s) to the right of the decimal point in the mask (register B). eg:<\/p>\n<pre>\r\n; press [5]\r\n;\r\n; which leads to:\r\n; P= 9 A= 12345000000000 B= 00020999999999 C= 01234000000002\r\n\r\n; if this is digit 2+ (but after . pre EEX: s2=1 s7=0)\r\n01153 if p # 3\r\n01154 goto 01366\r\n01366 if s1 = 0          ; if not input_started (not digit 1)\r\n01367 goto 01361\r\n01370 if s2 = 0          ; if not dot_pressed\r\n01371 goto 01107\r\n; then\r\n01372 p - 1 -&gt; p         ; P= 8\r\n01373 0 -&gt; b[p]          ; B= 00020099999999\r\n01374 jsb 01156\r\n01156 ...\r\n(as above)\r\n; S= .12......9.b f= .12..5..\r\n; A= 01234500000000 C= 01234500000002 P= 12\r\n00621 goto 00531 <\/pre>\n<p>The mask now looks like &#8220;00020099999999&#8221;. There are two &#8220;holes&#8221; in the mask to the right of the decimal point to allow the &#8220;4&#8221; and &#8220;5&#8221; to show through. We see &#8221; 123.45&#8243;.<\/p>\n<p>The C register contains 1.2345e2 or 123.45<\/p>\n<p>Pressing EEX activates another part of the number entry microcode. It looks like: <\/p>\n<pre>\r\n; press [EEX]\r\n; key scan  addr  instr\r\n; EEX (072) 01072 goto 01277\r\n;\r\n; which leads to:\r\n01277 if c[m] &gt;= 1       ; if prefix(es)\r\n01300 goto 01047\r\n01301 1 -&gt; s7            ; S= .12....7.... (eex_pressed)\r\n01302 if s1 = 0          ; if not input_started\r\n01303 goto 01004         ; (put a 1 in mantissa)\r\n01304 c &lt;-&gt; m            ; C= 01234500000002 M= 00000000000221\r\n01305 shiftr a[w]        ; A= 01234500000000\r\n01306 jsb 01157\r\n\r\n01157 c -&gt; a[s]          ; get the sign from stack X\r\n; if EEX was pressed show exponent digits\r\n01160 if s7 = 0\r\n01161 goto 01163\r\n01162 0 -&gt; b[x]          ; B= 00020099999000\r\n; endif\r\n01163 1 -&gt; s9            ; S= .12....7.9.. (display_input)\r\n01164 0 -&gt; f3            ; S= .12....7.9.b f= .12..5.. (not display_x)\r\n01165 1 -&gt; f1            ; set auto_enter\r\n01166 rom 1\r\n00567 a &lt;-&gt; c[w]         ; A= 01234500000002 C= 01234500000000\r\n00570 c -&gt; a[w]          ; A= 01234500000000\r\n00571 if a[m] &gt;= 1\r\n00572 goto 00546\r\n00546 c + 1 -&gt; c[xs]     ; C= 01234500000100 (if c[xs]=9 dont goto...)\r\n00547 goto 00470\r\n00470 0 -&gt; c[xs]         ; C= 01234500000000\r\n00471 13 -&gt; p            ; P= 13\r\n00472 c - 1 -&gt; c[x]      ; C= 01234500000999\r\n00473 if b[p] = 0\r\n00474 goto 00463\r\n00463 p - 1 -&gt; p         ; P= 12\r\n00464 c + 1 -&gt; c[x]      ; C= 01234500000000\r\n00465 jsb 00473\r\n; P=11 C= 01234500000001\r\n; P=10 C= 01234500000002 (=1.2345e2 \"123.45\")\r\n00465 jsb 00473\r\n00473 if b[p] = 0\r\n00474 goto 00463\r\n00475 12 -&gt; p            ; P= 12\r\n00476 if a[p] &gt;= 1\r\n00477 goto 00574\r\n00574 a &lt;-&gt; c[m]\r\n00575 rom 2\r\n01176 if c[xs] = 0\r\n01177 goto 01334\r\n01334 if c[m] &gt;= 1\r\n01335 goto 01337\r\n01337 if p # 14\r\n01340 goto 01217\r\n01217 rom 1\r\n00620 if s8 = 0\r\n00621 goto 00531 <\/pre>\n<p>We see the &#8221; 00&#8243; bit on the end (right) of the number keyed in so far. Then when we add more digits, these go into the exponent: <\/p>\n<pre>\r\n; press [7]\r\n;\r\n; which leads to:\r\n; A= 12345000000007\r\n02506 if c[m] = 0        ; if no prefix(es)\r\n; put C and M back\r\n02507 goto 02736\r\n02736 c &lt;-&gt; m            ; C= 01234500000002 M= 00000000000221\r\n02737 if s3 = 0          ; if in RUN mode\r\n02740 goto 02511\r\n02511 rom 2\r\n01112 if s1 = 0          ; if not input_started\r\n01113 goto 01245         ; but it has\r\n01114 if s7 = 0          ; if not eex_pressed\r\n01115 goto 01130         ; but it was\r\n01116 a &lt;-&gt; c[x]         ; A= 12345000000002 C= 01234500000007\r\n01117 shiftr a[w]        ; A= 01234500000000\r\n01120 1 -&gt; p             ; P= 1\r\n01121 c -&gt; a[wp]         ; A= 01234500000007\r\n01122 goto 01157\r\n01157 ...\r\n; S= .12....7.9.b f= .12..5..\r\n; C= 01234500000009 P= 12\r\n00621 goto 00531\r\n\r\n; press [8]\r\n;\r\n; which leads to:\r\n; A= 12345000000078\r\n02506 if c[m] = 0        ; if no prefix(es)\r\n02507 goto 02736\r\n; put C and M back\r\n02736 c &lt;-&gt; m            ; C= 01234500000009 M= 00000000000221\r\n02737 if s3 = 0          ; if in RUN mode\r\n02740 goto 02511\r\n02511 ...\r\n; S= .12....7.9.b f= .12..5..\r\n; A= 01234500000078 C= 01234500000080 P=12\r\n00621 goto 00531 <\/pre>\n<p>The &#8220;7&#8221; went into the rightmost exponent digit. Then, the &#8220;8&#8221; pushed the &#8220;7&#8221; to the left and took the rightmost position.<\/p>\n<p>Note that the exponent in the C register is &#8220;80&#8221;. This is because we keyed in &#8220;123.45e78&#8221; and that should be &#8220;1.2345e80&#8221; in normal scientific notation. It has added the e2 from keying in &#8220;123&#8221; to the e78 we entered into the exponent and come up with e80.<\/p>\n<p>The display value (A register content) still shows exactly what you keyed in &#8220;123.45e78&#8221;. <\/p>\n<p>If you press CHS at this point it affects the exponent sign like this: <\/p>\n<pre>\r\n; press [CHS]\r\n; key scan  addr  instr\r\n; CHS (073) 01073 goto 01375\r\n;\r\n; which leads to:\r\n01375 if c[m] = 0        ; if no prefix(es)\r\n01376 goto 01140\r\n01140 c &lt;-&gt; m            ; C= 01234500000080 M= 00000000000221\r\n01141 shiftr a[w]        ; A= 01234500000078\r\n01142 if s7 = 0          ; if not eex_pressed\r\n01143 goto 01227         ; but it was\r\n01144 a &lt;-&gt; c[x]         ; A= 01234500000080 C= 01234500000078\r\n01145 0 - c - 1 -&gt; c[xs] ; C= 01234500000978\r\n01146 a &lt;-&gt; c[x]         ; A= 01234500000978 C= 01234500000080\r\n01147 goto 01157\r\n01157 ...\r\n; S= .12....7.9.b f= .12..5..\r\n; A= 01234500000978 P=12 C= 01234500000924\r\n00621 goto 00531 <\/pre>\n<p>The A register has a &#8220;9&#8221; in the exponent sign position. This will show as a &#8220;-&#8221; in front of the other exponent digits &#8220;78&#8221;.<\/p>\n<p>The C register exponent is e924. This is 1000 + -76. The exponent in the C register is -76. Your HP-65 calculator has converted &#8220;123.45e-78&#8221; to &#8220;1.2345*10^2 e-78&#8221; or &#8220;1.2345e(2-78)&#8221; = &#8220;1.2345e-76&#8221;. e-76 is 100 times more than e-78, just like e80 is 100 times more than e78, because we keyed in 100 (and a bit) e-78.<\/p>\n<p>For a full trace of the microcode for this key sequence, see <a href=\"http:\/\/www.sydneysmith.com\/products\/gss-hp65\/downloads\/65-123.45e78-.txt\" target=\"_blank\">65-123.45e78-.txt<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Here&#8217;s what happens when you press 123.45 EEX 78 CHS.<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[16,5,39],"tags":[37,32],"_links":{"self":[{"href":"https:\/\/www.sydneysmith.com\/wordpress\/wp-json\/wp\/v2\/posts\/1489"}],"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=1489"}],"version-history":[{"count":4,"href":"https:\/\/www.sydneysmith.com\/wordpress\/wp-json\/wp\/v2\/posts\/1489\/revisions"}],"predecessor-version":[{"id":1493,"href":"https:\/\/www.sydneysmith.com\/wordpress\/wp-json\/wp\/v2\/posts\/1489\/revisions\/1493"}],"wp:attachment":[{"href":"https:\/\/www.sydneysmith.com\/wordpress\/wp-json\/wp\/v2\/media?parent=1489"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.sydneysmith.com\/wordpress\/wp-json\/wp\/v2\/categories?post=1489"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.sydneysmith.com\/wordpress\/wp-json\/wp\/v2\/tags?post=1489"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}