{"id":26876934,"url":"https://github.com/biged/square-root-code","last_synced_at":"2026-01-08T12:49:42.036Z","repository":{"id":282249949,"uuid":"947965887","full_name":"BigEd/square-root-code","owner":"BigEd","description":"investigate square root code from Acorn's Basics","archived":false,"fork":false,"pushed_at":"2025-03-21T18:43:14.000Z","size":297,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-21T19:42:32.129Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/BigEd.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-03-13T14:29:20.000Z","updated_at":"2025-03-21T18:43:18.000Z","dependencies_parsed_at":"2025-03-13T15:44:51.158Z","dependency_job_id":null,"html_url":"https://github.com/BigEd/square-root-code","commit_stats":null,"previous_names":["biged/square-root-code"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BigEd%2Fsquare-root-code","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BigEd%2Fsquare-root-code/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BigEd%2Fsquare-root-code/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BigEd%2Fsquare-root-code/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/BigEd","download_url":"https://codeload.github.com/BigEd/square-root-code/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246458007,"owners_count":20780679,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-03-31T11:17:41.096Z","updated_at":"2026-01-08T12:49:41.979Z","avatar_url":"https://github.com/BigEd.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# square-root-code\ninvestigate square root code from Acorn's Basics\n\nIn particular, 6502 code found in Basic versions 2, 4 and 4r32, and ARM code found in Basic V, 1987.\n\nThis repo is a companion to the stardot thread [Basic's square root algorithm](https://stardot.org.uk/forums/viewtopic.php?t=30662)\n\nResources:\n- b2 emulator in [debug mode](https://github.com/tom-seddon/b2/blob/master/doc/Debug-version.md)\n- [basic 2 disassembly](https://archive.org/details/BBCMicroCompendium/page/419/mode/1up) by Jeremy Ruston\n- [basic 4 disassembly](https://8bs.com/basic/basic4-a7b5.htm#A7B5) at 8bs\n- [basic 4r32 dissassembly](https://github.com/hoglet67/BBCBasic4r32/blob/master/disassembly/Basic432.asm#L7737) by hoglet\n- basic V arm code [at gtoal's site](https://gtoal.com/acorn/arm/Basic/)\n\nPreliminary findings:\n\nBy timing Basic code we can profile the square root function in three versions of 6502 Basic. Code suggested by Dominic Beesley - subtract the cost of a loop which only assigns from the cost of a loop which does a square root.\n\n```\n100 p=PI:e=EXP1:r=p/e:T=TIME\n110 FORi=0TO999:x=x:NEXT\n120 E=TIME-T\n160 T=TIME\n170 FORi=0TO999:x=SQRr:NEXT\n180 PRINT TIME-T-E\n```\n\nResults from b2 emulator:\n- 9.20s on beeb, basic 2, copyright 1982\n- 2.02s on master 128, os 3.20, basic 4, copyright 1984\n- 1.19s on master 128, os 3.50, basic 4.32, copyright 1988\n\nTimings from tracing execution of a single calculation of the square root of 2, on real hardware, using 6502Decoder:\n\n- 17407 cycles, 4844 ins, 3.59 cpi with Basic 2\n- 3921 cycles, 1169 ins, 3.35 cpi with Basic 4\n- 2179 cycles, 702 ins, 3.10 cpi with Basic 4r32\n\nWe notice that the later code uses cheaper (simpler) instructions, as well as fewer of them.\n\nLooking at instruction mixes, we see\n\n- basic 2 uses 1506 shifts, 1277 load/store, 513 add/sub/compare, 836 branches\n- basic 4 uses 248 shifts, 377 load/store, 141 add/sub/compare, 168 branches\n- basic 4r32 uses 139 shifts, 159 load/store, 91 add/sub/compare, 134 branches\n\n(Using `egrep -c -i -w` with one of `'asl|lsr|ror|rol'`, `'lda|sta'`, `'adc|sbc|cmp'`, `'b[a-z][a-z]'`)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbiged%2Fsquare-root-code","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbiged%2Fsquare-root-code","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbiged%2Fsquare-root-code/lists"}