{"id":410989,"date":"2024-06-29T21:42:29","date_gmt":"2024-06-29T21:42:29","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=410989"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=410989","title":{"rendered":"<span>Koyaanisqatsi: The WYSIWYG-style byte-code CPU<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-1\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/post_images\/6cf\/09d\/4dd\/6cf09d4dd7f5c69ebbb98a4b01b2d3ad.png\" alt=\"Draft diagram of core\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/6cf\/09d\/4dd\/6cf09d4dd7f5c69ebbb98a4b01b2d3ad.png\"\/><\/p>\n<p>  <a href=\"https:\/\/drive.google.com\/uc?export=view&amp;id=1GkfehTQ7mfeUWR9wkxka755pGWIdNNjH\" rel=\"nofollow noopener noreferrer\">SVG-File (actual draft)<\/a>  <\/p>\n<div class=\"oembed\">\n<div class=\"tm-iframe_temp\" data-src=\"https:\/\/embedd.srv.habr.com\/iframe\/5fd5fdb305d782142ffea515\" data-style=\"\" id=\"5fd5fdb305d782142ffea515\" width=\"\"><\/div>\n<\/div>\n<p>  <\/p>\n<h4>Lyrics<\/h4>\n<p>  Ancient times are known to everyone not with immortal works from Homer&#8217;s only, but also with the Pythagorean multiplication table, Euclidean geometry and the Archimedes screw and the Pi, which we learned to use only relatively recently. In antiquity the art was not only to be able to write poetry and prose, but to design catapults or battering tools also, now there are rigid frameworks, when the discovering the new another beautiful formula is a formal words play only.<br \/>  Mathematics rules the modern world completely, cynically intertwining with the world of art, intruding with calculations in all spheres of our recreation and everyday life, when the colors of masterpieces turning into poisonous colours.<br \/>  <a name=\"habracut\"><\/a><br \/>  The same dry economy, with its numbers, forced Intel engineers to simplify the first processor, for the compatibility with not the best <a href=\"https:\/\/en.wikipedia.org\/wiki\/Datapoint_2200\" rel=\"nofollow noopener noreferrer\">architecture\u00a0of\u00a0time<\/a>, their sprint desire to throw their chip with ugly architecture to mass market. No one thought that the ugly machine code would become a world-class standard, which could not be looked at without pain and shame, where nobody thinking for switch from the latency nanoseconds to the aesthetic picture of their product: It is no longer important what such goals were then pursued by engineers, when superscalar the core of any modern processor, support for the x86 instructions has long been accomplished by the emulation level as a formality of marketing.<\/p>\n<h4>Koyaanisqatsi \u2014 like a cry from the heart!<\/h4>\n<p>  In contrast to the well-known Intel processors, Koyaanisqatsi was conceived as a difficult named with easy to understand and learn to program it at the level of machine code in dump editors with no translators of a high-level languages.<\/p>\n<h4>Introduction<\/h4>\n<p>  The wild design of the processor was conceived as a joke controller with byte-code which ability to encode a script dump even without having to refer to the command table before learning them completely and whole task was set to design a simple processor device in which any of the 30 APRs can be replaced with any peripherals as sensors or motors in a unique opportunity to organize as direct interaction of all required devices without the need for mad high performance.<\/p>\n<p>  So, <a href=\"https:\/\/www.lexaloffle.com\/pico-8.php\" rel=\"nofollow noopener noreferrer\">PICO-8<\/a> and <a href=\"https:\/\/gigatron.io\/\" rel=\"nofollow noopener noreferrer\">Gigatron<\/a>, as well as <a href=\"http:\/\/www.megaprocessor.com\/\" rel=\"nofollow noopener noreferrer\">MegaProcessor<\/a> or <a href=\"http:\/\/mycpu.eu\/\" rel=\"nofollow noopener noreferrer\">MyCPU<\/a>, although developed by specialists, no one approached the issue with a esthetic of machine coding.<\/p>\n<h4>Processor architecture<\/h4>\n<p>  From start of design this processor, there was no goal of achieving at partial compatibility with any of the existing architecture by world leading industry.<\/p>\n<p>  But the main goal was to develop a processor, hexadecimal encoding in the dump of all instructions without assembler, when the byte nibbles themselves should represent the abbreviations of the instructions themselves \u2014 not binary encode some abstract bytecode with esoteric bit fields, like reg\/mod bits in the x86.<\/p>\n<h4>Register file<\/h4>\n<p>  Processor is based on a register file of four functional groups with ten cells each. Any ALU operations are possible on any registers, but exist simple rules for correct operation with them. Here we need to remember the purpose of these functional groups:<\/p>\n<div class=\"scrollable-table\">\n<table>\n<tr>\n<th>Group<\/th>\n<th>Function<\/th>\n<th>Notes<\/th>\n<\/tr>\n<tr>\n<td>A\u2080\u2026\u2089<\/td>\n<td>Accumulators<\/td>\n<td>A\u2080 is PSW of ALU<\/td>\n<\/tr>\n<tr>\n<td>B\u2080\u2026\u2089<\/td>\n<td>Base \/ Block<\/td>\n<td>B\u2080 store memory Block for RET-instruction<\/td>\n<\/tr>\n<tr>\n<td>C\u2080\u2026\u2089<\/td>\n<td>Cell \/ Counter<\/td>\n<td>C\u2080 store memory Cell for RET-instruction<\/td>\n<\/tr>\n<tr>\n<td>D\u2080\u2026\u2089<\/td>\n<td>Device<\/td>\n<td>Any in\/out-Devices, like i8253, i8255 or i8257\u00b9<\/td>\n<\/tr>\n<\/table>\n<\/div>\n<p>\u00b9: D\u2089 can switching upto 256 pages of D\u2080\u2026D\u2088 for any user-purpose units<\/p>\n<h4>Subroutines<\/h4>\n<p>  This processor is simple and doesn&#8217;t have built-in any hardware for organizing stack operations, the B\u2080:C\u2080 registers saving the pointer for return to caller. If necessary, the programmer himself is obliged to take care of all operations with the stack and describe them with an algorithm, when should use library of virtual instructions for branching and call with a stack at the program level.<\/p>\n<h4>Koyaanisqatsi Command System<\/h4>\n<p>  A bytecode are transparently encoded in WYSIWYG:\u201cWhat I see means what I see\u201d. Hexadecimal encoding is the abbreviation of the command itself, and everything was conceived so that most of the commands just perform understandable action.<\/p>\n<ul>\n<li>00: HLT (program stop) \u2014 logical and harmonious code!<\/li>\n<li>01\u202699: The BCD-code as prefixed Byte-Code-Data for expand next instruction<\/li>\n<li>A0\u2026A9, B0\u2026B9, C0\u2026C9: Timeless prefixes for selecting the active register of the specified group \u2014 A\u2080\u2026A\u2089, B\u2080\u2026B\u2089, C\u2080\u2026C\u2089 respectively<\/li>\n<li>D0\u2026D9: Selection of the active device of the Devices group \u2014 D\u2080\u2026D\u2089<\/li>\n<li>AA\u2026AD: Timeless prefixes for choosing a combination of operands for ALU operations \u2014 A,A; A,B; A,C; A,D respectively<\/li>\n<li>BA\u2026BD: Timeless prefixes for choosing a combination of operands for ALU operations \u2014 B,A; B,B; B,C; B,D respectively<\/li>\n<li>CA\u2026CD: Timeless prefixes for choosing a combination of operands for ALU operations \u2014 C,A; C,B; C,C; C,D respectively<\/li>\n<li>DA\u2026DD: Timeless prefixes for choosing a combination of operands for ALU operations \u2014 D,A; D,B; D,C; D,D respectively<\/li>\n<li>E0\u2026EF: Calling an Extension via a subroutine \u2014 CALL 0xE000\u20260xEF00<\/li>\n<li>F0\u2026FF: Call to the Function with the specified index \u2014 CALL 0xF000\u20260xFF00<\/li>\n<li>AE \/ BE \/ CE \/ DE: Conditional Return by active Flag existing (ZF \/ SF \/ CF \/ PO)<\/li>\n<li>AF \/ BF \/ CF \/ DF: Conditional Return by Fictive PSW-Flags (NZ \/ NS \/ NC \/ PE)<\/li>\n<li>0A \/ 1A \/ 2A\u20269A: ALU-operation \u00abSum\u00bb (Add) over a group of operands \u2014 the index of the right operand is specified explicitly 0\u20269<\/li>\n<li>0B \/ 1B \/ 2B\u20269B: ALU-operation \u00abSubtraction\u00bb (suB) on a group of operands \u2014 the index of the right operand is specified explicitly 0\u20269<\/li>\n<li>0C \/ 1C \/ 2C\u20269C: ALU-operation \u00abConjunction\u00bb (Conjunct \/ and) on a group of operands \u2014 the index of the right operand is specified explicitly 0\u20269<\/li>\n<li>0D \/ 1D \/ 2D\u20269D: ALU-operation \u00abDisjunct \/ or\u00bb on a group of operands \u2014 the index of the right operand is specified explicitly 0\u20269<\/li>\n<li>0E \/ 1E \/ 2E\u20269E: ALU-operation \u00abExclusive OR\u00bb (Exclusive or \/ Eor \/ xor) on a group of operands \u2014 the index of the right operand is specified explicitly 0\u20269<\/li>\n<li>0F \/ 1F \/ 2F\u20269F: MOV-operation \u00abFOR\u00bb with group of operands \u2014 the index of the right operand is specified explicitly 0\u20269<\/li>\n<\/ul>\n<p>  <\/p>\n<h4>Koyaaniskatsi programming basics<\/h4>\n<p>  However, we shouldn&#8217;t think that the WYSIWYG-processor requires nothing at all from an advanced user-programmer: You still have to overcome the minimum entry threshold\u2026<\/p>\n<p>  For example, addition of values \u200b\u200bfrom registers A\u2081 and B\u2082 can be represented by the expression \u00abA1\u00a0+=\u00a0B2\u00bb or the mnemonic notation \u00abADD\u00a0A1,B2\u00bb, what should be translate into machine code. The processor architecture is simple and based in Polish notation, we necessary to predefine the operands used in the operation.<\/p>\n<p>  Since the combination of registers \u00abA1\u00bb and \u00abB2\u00bb is used in the order \u00abAn,Bn\u00bb, the machine code AB\u2081\u2086 must be specified under their definition. And indixes of specific operands is performed by codes A1\u2081\u2086 and B2\u2081\u2086 encoding a machine code. Since the index of the right operand is equal to \u00abB2\u00bb, then in the code of the ALU-operation \u00abAdd\u00bb it should be indicated in the left-hand nibble as 2A\u2081\u2086. It<br \/>  becomes obvious that the code of the whole expression is \u00abA1\u00a0AB\u00a0B2\u00a02A\u00bb. The B\u2082 is no destination accumulator of result and it explicitly indicated in the ALU operation, the command byte \u00abB2\u00bb can be excluded from the chain and this codes will be reduced to one combination of \u00abA1\u00a0AB\u00a02A\u00bb or \u00abAB\u00a0A1\u00a02A\u00bb.<\/p>\n<p>  The expression \u00abA1\u00a0=\u00a0A1\u00a0+\u00a0B2\u00a0&#8212;\u00a0B3\u00a0&amp;\u00a0B4\u00a0|\u00a0B5\u00a0^\u00a0B6\u00bb can be described by the code \u00abA1\u00a0AB\u00a02A\u00a03B\u00a04C\u00a05D\u00a06E\u00bb, since each next instruction code contains the index of the right operand, which allows we to encode in a compact and eficient manner.<\/p>\n<h4>Links<\/h4>\n<p>  Raw files of project is placed <a href=\"https:\/\/github.com\/Alikberov\/Koyaanisqatsi\" rel=\"nofollow noopener noreferrer\">here<\/a>.<br \/>  Raw Verilog-model placed at <a href=\"https:\/\/edaplayground.com\/x\/3mdG\" rel=\"nofollow noopener noreferrer\">here<\/a>.<br \/>  Web-emulator with assemler\/disassembler and tiny demo placed at <a href=\"https:\/\/gistpreview.github.io\/?cff9df3bc1901d33f5c055682721240a#autorun\" rel=\"nofollow noopener noreferrer\">here<\/a>\u2026<br \/>  Retro i8080-emulator for Koy-Code \u2014 <a href=\"https:\/\/rk86.ru\/index.html?file=https:\/\/gist.githubusercontent.com\/Alikberov\/8016708c5ea229da0a0e5af456965743\/raw\/i8080-koy-mac-emu.json\" rel=\"nofollow noopener noreferrer\">here<\/a>.<br \/>  Wiki<sub>esolangs<\/sub> page index is <a href=\"https:\/\/esolangs.org\/wiki\/Koyaanisqatsi\" rel=\"nofollow noopener noreferrer\">here<\/a>.<br \/>  Forum<sub>anycpu<\/sub> subject index is <a href=\"http:\/\/anycpu.org\/forum\/viewtopic.php?f=23&amp;t=823\" rel=\"nofollow noopener noreferrer\">here<\/a>.<br \/>  Original project index is <a href=\"https:\/\/habr.com\/ru\/post\/505296\/\">here<\/a><sup>ru<\/sup>\u2026<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/542370\/\"> https:\/\/habr.com\/ru\/articles\/542370\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-1\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/post_images\/6cf\/09d\/4dd\/6cf09d4dd7f5c69ebbb98a4b01b2d3ad.png\" alt=\"Draft diagram of core\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/6cf\/09d\/4dd\/6cf09d4dd7f5c69ebbb98a4b01b2d3ad.png\"\/><\/p>\n<p>  <a href=\"https:\/\/drive.google.com\/uc?export=view&amp;id=1GkfehTQ7mfeUWR9wkxka755pGWIdNNjH\" rel=\"nofollow noopener noreferrer\">SVG-File (actual draft)<\/a>  <\/p>\n<div class=\"oembed\">\n<div class=\"tm-iframe_temp\" data-src=\"https:\/\/embedd.srv.habr.com\/iframe\/5fd5fdb305d782142ffea515\" data-style=\"\" id=\"5fd5fdb305d782142ffea515\" width=\"\"><\/div>\n<\/div>\n<p>  <\/p>\n<h4>Lyrics<\/h4>\n<p>  Ancient times are known to everyone not with immortal works from Homer&#8217;s only, but also with the Pythagorean multiplication table, Euclidean geometry and the Archimedes screw and the Pi, which we learned to use only relatively recently. In antiquity the art was not only to be able to write poetry and prose, but to design catapults or battering tools also, now there are rigid frameworks, when the discovering the new another beautiful formula is a formal words play only.<br \/>  Mathematics rules the modern world completely, cynically intertwining with the world of art, intruding with calculations in all spheres of our recreation and everyday life, when the colors of masterpieces turning into poisonous colours.  <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-410989","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/410989","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=410989"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/410989\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=410989"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=410989"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=410989"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}