{"id":1237,"date":"2015-11-08T06:43:25","date_gmt":"2015-11-08T06:43:25","guid":{"rendered":"http:\/\/www.sydneysmith.com\/wordpress\/?p=1237"},"modified":"2017-05-14T01:33:36","modified_gmt":"2017-05-14T01:33:36","slug":"hp67-user-program-counter","status":"publish","type":"post","link":"https:\/\/www.sydneysmith.com\/wordpress\/1237\/hp67-user-program-counter\/","title":{"rendered":"HP67 User Program Counter"},"content":{"rendered":"<p>The HP67 saves the user program counter in the bottom 3 nibbles (2,1,0) of ram[61]. However, you could be forgiven for thinking that those three digits don&#8217;t look anything like the program counter display. Here&#8217;s why<br \/>\n<!--more--><br \/>\nInternally it stores ram[61][2,1,0] as n,b,r where:<br \/>\nn is the instruction number (0-6) within the program register<br \/>\nb is the program ram bank (1-2)<br \/>\nr is the register (0-0x0f) within the ram bank.<\/p>\n<p>Program steps 001-112 reside in ram bank 2. You see this as registers 32-47 in the hp67u under menu, Advanced, View RAM.<\/p>\n<p>Program steps 113-224 reside in ram bank 1. This is registers 16-31 in the same menu option.<\/p>\n<p>Each ram register contains 14 nibbles (4 bit digits &#8211; these show up as &#8220;0&#8221;-&#8220;9&#8221; in data registers). When a ram register is used to store a program step, the full range of &#8220;0-9a-f&#8221; is used for each nibble &#8211; so don&#8217;t be too surprised if you see things in there other than &#8220;0&#8221;-&#8220;9&#8221;.<\/p>\n<p>Each merged user program step is stored internally as an 8-bit instruction so each program register stores 7 steps and each step is 2 nibbles long.<\/p>\n<p>This program:<\/p>\n<pre>\r\n001: 31 25 11\r\n002: 09\r\n003: 71\r\n004: 05\r\n005: 81\r\n006: 03\r\n007: 02\r\n008: 61\r\n009: 35 22\r\n010: 84\r\n011: 84\r\n<\/pre>\n<p>gets stored as:<\/p>\n<pre>\r\n45: 00000000000000\r\n46: 00000000000e37\r\n47: 12131e153919fa\r\n<\/pre>\n<p>&#8220;fa&#8221; is the 8-bit code for &#8220;31 25 11&#8221; (f LBL A).<\/p>\n<p>The content of ram[61] looks like this:<br \/>\n61: 0000000000042f<\/p>\n<p>That combination has b=2, r=0x0f(=15) and n=4.<\/p>\n<p>What you see displayed as the program step number is:<br \/>\n((b==2)? 120 : 232) &#8211; (r+1)*7 &#8211; (n+1)<br \/>\nIn this case:<br \/>\n=120 &#8211; (15+1)*7 &#8211; (4+1)<br \/>\n=120 &#8211; 16*7 &#8211; 5<br \/>\n=120 &#8211; 112 &#8211; 5 = 003<\/p>\n<p>Effectively the three n,b,r nibbles form a counter of<br \/>\n(0-6)*(1-2)*(0-15) = 7*2*16 = 2*112 = 224 (program steps).<\/p>\n<p>It&#8217;s hard for us to follow but it makes it easier for the calculator to find the next user program step:<br \/>\n&#8211; select ram bank 1 or 2<br \/>\n&#8211; access register 0-15 within that bank<br \/>\n&#8211; get the 0-6th set of 2 &#8220;digits&#8221; from that register.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The HP67 saves the user program counter in the bottom 3 nibbles (2,1,0) of ram[61]. However, you could be forgiven for thinking that those three digits don&#8217;t look anything like the program counter display. Here&#8217;s why<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[16,5,3],"tags":[33],"_links":{"self":[{"href":"https:\/\/www.sydneysmith.com\/wordpress\/wp-json\/wp\/v2\/posts\/1237"}],"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=1237"}],"version-history":[{"count":2,"href":"https:\/\/www.sydneysmith.com\/wordpress\/wp-json\/wp\/v2\/posts\/1237\/revisions"}],"predecessor-version":[{"id":1348,"href":"https:\/\/www.sydneysmith.com\/wordpress\/wp-json\/wp\/v2\/posts\/1237\/revisions\/1348"}],"wp:attachment":[{"href":"https:\/\/www.sydneysmith.com\/wordpress\/wp-json\/wp\/v2\/media?parent=1237"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.sydneysmith.com\/wordpress\/wp-json\/wp\/v2\/categories?post=1237"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.sydneysmith.com\/wordpress\/wp-json\/wp\/v2\/tags?post=1237"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}