{"id":45,"date":"2008-10-16T11:47:40","date_gmt":"2008-10-16T19:47:40","guid":{"rendered":"http:\/\/www.pagetable.com\/?p=45"},"modified":"2008-10-16T11:47:40","modified_gmt":"2008-10-16T19:47:40","slug":"ror-in-microsoft-basic-for-6502","status":"publish","type":"post","link":"https:\/\/www.pagetable.com\/?p=45","title":{"rendered":"&#034;ROR&#034; in Microsoft BASIC for 6502"},"content":{"rendered":"<p>If you disassemble any version of Microsoft BASIC for 6502, you&#8217;ll find this code in a function that normalizes the (simulated) floating point accumulator:<\/p>\n<pre>\nNORMALIZE_FAC6:\n\tinc\tFAC\t\t; MANTISSA CARRIED, SO SHIFT RIGHT\n\tbeq\tOVERFLOW\t; OVERFLOW IF EXPONENT TOO BIG\n\tror\tFAC+1\n\tror\tFAC+2\n\tror\tFAC+3\n\tror\tFAC+4\n\tror\tFACEXTENSION\n\trts\n<\/pre>\n<p>Well, not any BASIC. All versions of<\/p>\n<ul>\n<li>Commodore BASIC (all versions, since 1977)<\/li>\n<li>AppleSoft BASIC (all versions, since 1977)<\/li>\n<li>Microsoft BASIC for the OHIO Scientific (all versions, since 1977)<\/li>\n<li>Microsoft BASIC for the rare Mattel Intellivision Keyboard Component (1980)<\/li>\n<\/ul>\n<p>use this code, but if you look at the disassembly of<\/p>\n<ul>\n<li>Microsoft BASIC for the MOS KIM-1 (1977)<\/li>\n<li>Microsoft BASIC for the Tangerine Microtan 65 (1979)<\/li>\n<\/ul>\n<p>you will see this code instead:<\/p>\n<pre>\nNORMALIZE_FAC6:\n        inc     FAC\n        beq     OVERFLOW\n        lda     #$00\n        bcc     @1\n        lda     #$80\n@1:\n        lsr     FAC+1\n        ora     FAC+1\n        sta     FAC+1\n        lda     #$00\n        bcc     @2\n        lda     #$80\n@2:\n        lsr     FAC+2\n        ora     FAC+2\n        sta     FAC+2\n        lda     #$00\n        bcc     @3\n        lda     #$80\n@3\n        lsr     FAC+3\n        ora     FAC+3\n        sta     FAC+3\n        lda     #$00\n        bcc     @4\n        lda     #$80\n@4:\n        lsr     FAC+4\n        ora     FAC+4\n        sta     FAC+4\n        lda     #$00\n        bcc     @5\n        lda     #$80\n@5:\n        lsr     FACEXTENSION\n        ora     FACEXTENSION\n        sta     FACEXTENSION\n        rts\n<\/pre>\n<p>(Actually, the OHIO Scientific and Intellivision versions work on a 3 byte (&#8220;6 digit&#8221;) instead of a 4 byte (&#8220;9 digit&#8221;) mantissa, so the &#8220;FAC+4&#8221; part is missing.)<\/p>\n<p>Similar replacement has happened in other parts of the floating point library. It seems to be a compile-time option of the assembly source code.<\/p>\n<p>Todays puzzle is to find out why there are two versions of this code, and why the different computer vendors chose to use one version or another.<\/p>\n<p><i>See <a href=\"http:\/\/www.pagetable.com\/?p=45#comments\">comments<\/a> for solution.<\/i><\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you disassemble any version of Microsoft BASIC for 6502, you&#8217;ll find this code in a function that normalizes the (simulated) floating point accumulator: NORMALIZE_FAC6: inc FAC ; MANTISSA CARRIED, SO SHIFT RIGHT beq OVERFLOW ; OVERFLOW IF EXPONENT TOO BIG ror FAC+1 ror FAC+2 ror FAC+3 ror FAC+4 ror FACEXTENSION rts Well, not any &#8230; <a title=\"&#034;ROR&#034; in Microsoft BASIC for 6502\" class=\"read-more\" href=\"https:\/\/www.pagetable.com\/?p=45\" aria-label=\"Read more about &#034;ROR&#034; in Microsoft BASIC for 6502\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,5,6,26],"tags":[],"class_list":["post-45","post","type-post","status-publish","format-standard","hentry","category-2","category-archeology","category-basic","category-puzzle"],"_links":{"self":[{"href":"https:\/\/www.pagetable.com\/index.php?rest_route=\/wp\/v2\/posts\/45","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.pagetable.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.pagetable.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.pagetable.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.pagetable.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=45"}],"version-history":[{"count":0,"href":"https:\/\/www.pagetable.com\/index.php?rest_route=\/wp\/v2\/posts\/45\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.pagetable.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=45"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.pagetable.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=45"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.pagetable.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=45"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}