{"id":776,"date":"2020-06-17T15:36:00","date_gmt":"2020-06-17T21:36:00","guid":{"rendered":"https:\/\/www.great-white-software.com\/blog\/?p=776"},"modified":"2020-06-12T11:16:57","modified_gmt":"2020-06-12T17:16:57","slug":"byte-code-interpreter","status":"publish","type":"post","link":"https:\/\/www.great-white-software.com\/blog\/2020\/06\/17\/byte-code-interpreter\/","title":{"rendered":"Byte code interpreter"},"content":{"rendered":"\n<p>One day on <a href=\"https:\/\/ifnotnil.com\">IfNotNil<\/a> we were discussing byte code and interpreters. <\/p>\n\n\n\n<p>And the conversation came around to old CPU&#8217;s like the 6502. One many folks cut their teeth on. My first computer was a <a href=\"https:\/\/en.wikipedia.org\/wiki\/TRS-80_Color_Computer\">TRS-80 CoCo<\/a> and after than I stepped up to an IBM clone; a <a href=\"https:\/\/en.wikipedia.org\/wiki\/Texas_Instruments_Professional_Computer_and_Professional_Portable_Computer\">TI Professional<\/a> which lasted me through University and up until I started my first job after school.<\/p>\n\n\n\n<p>As part of the discussion it was hinted that writing a byte code interpreter for any one of several old 8 bit CPU&#8217;s might be an interesting diversion. And it might also prove to be useful as a learning exercise for others.<\/p>\n\n\n\n<p>Since the 6502 is an 8 bit only machine it basically is a &#8220;byte code&#8221; interpreter by its very definition. Each opcode is entirely contained in one byte &#8211; instead of like some current machines today that have very wide opcodes.<\/p>\n\n\n\n<p>As such its possible to encode EVERY opcode and an associated handler in a simple table of 255 entries that, when an opcode is encountered, the handler is fetched from a table of handlers and invoked. <\/p>\n\n\n\n<p>Those handlers are  all 0 parameter methods that fetches whatever necessary operands it requires, executes the specific instruction, sets registers, and returns.<\/p>\n\n\n\n<p>Here&#8217;s <a href=\"https:\/\/github.com\/npalardy\/6502-Emulator\">my evolving project on GitHub<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>One day on IfNotNil we were discussing byte code and interpreters. And the conversation came around to old CPU&#8217;s like the 6502. One many folks cut their teeth on. My first computer was a TRS-80 CoCo and after than I stepped up to an IBM clone; a TI Professional which lasted me through University and &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.great-white-software.com\/blog\/2020\/06\/17\/byte-code-interpreter\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Byte code interpreter&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-776","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/posts\/776","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/comments?post=776"}],"version-history":[{"count":1,"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/posts\/776\/revisions"}],"predecessor-version":[{"id":777,"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/posts\/776\/revisions\/777"}],"wp:attachment":[{"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/media?parent=776"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/categories?post=776"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/tags?post=776"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}