{"id":178,"date":"2022-02-08T20:52:10","date_gmt":"2022-02-09T01:52:10","guid":{"rendered":"https:\/\/paulcarbone.com\/50days\/?p=178"},"modified":"2022-02-08T20:59:44","modified_gmt":"2022-02-09T01:59:44","slug":"day-12","status":"publish","type":"post","link":"https:\/\/paulcarbone.com\/50days\/2022\/02\/08\/day-12\/","title":{"rendered":"Day 12: Hello World in Assembly"},"content":{"rendered":"\n<p>Yesterday proved I need to take a step back.  So let me actually take my time and write a proper &#8216;Hello World&#8217; program.  I&#8217;m going to do this in VS Code, since it&#8217;s just nicer to type on a 21st century editor (no offense, ZDE, you were totally awesome for the early 80s). <\/p>\n\n\n\n<p>First thing I need to figure out is where does the stack start? I was originally confused at putting the top of the stack at 00 (where there&#8217;s a bunch of BDOS vectors), but I think that really translates to 100H, the top of the TPA, which we set with the ORG pseudo-instruction.<\/p>\n\n\n\n<p>In the following example, I&#8217;m using both the write character call, 2, and the write string call, 9.  Write string is handy &#8211; it handles the looping for you, you just have to put the address of the beginning of the string in the DE register.  The only downside is the string is terminated with &#8216;$&#8217; so the string can&#8217;t contain that character.   There&#8217;s a good overview of all the <a href=\"https:\/\/www.seasip.info\/Cpm\/bdos.html\">BDOS calls here.<\/a><\/p>\n\n\n\n<p>A few other learnings: <\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>ZDE has both hard and soft tabs. I think if it detects hard tabs in the file, it switches to that mode.  Likewise, you should set VS Code to use hard tabs, 8 spaces.  <\/li><li>I thought some other assembler had a label limit of 5 characters, but it&#8217;s more like 16 on Z80ASM.  I&#8217;m trying to limit to 6 just for formatting (any longer and I need another tab)<\/li><li>Make sure to set your editor to use CR &amp; LF.  I don&#8217;t think the assembler had a problem with LF only, but you need both for proper formatting in ZDE, which is handy if you want to make a quick edit &#8216;on the box&#8217;. <\/li><\/ul>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><div><code class=\"hljs language-php\">;HELLO WORLD <span class=\"hljs-keyword\">FOR<\/span> Z80 ASSEMBLER\n;Z80ASM BY SLR SYSTEMS\n\n;SETUP \nBDOS\tEQU\t<span class=\"hljs-number\">5<\/span>\t\t;CALL <span class=\"hljs-keyword\">FOR<\/span> BDOS FUNCTIONS\nWCHR\tEQU\t<span class=\"hljs-number\">2<\/span>\t\t;WRITE CHARACTER, IN REG C\nWSTR\tEQU\t<span class=\"hljs-number\">9<\/span>\t\t;WRITE STRING, IN REG C\nRCHR\tEQU\t<span class=\"hljs-number\">1<\/span>\t\t;READ CHAR, IN REG C\nRBOOT\tEQU\t<span class=\"hljs-number\">0<\/span>\t\t;<span class=\"hljs-keyword\">RETURN<\/span> TO CP\/M\nTPA\tEQU\t<span class=\"hljs-number\">100<\/span>H\t\t;TRANSIENT PROGRAM AREA, START HERE\nCR \tEQU\t<span class=\"hljs-number\">0<\/span>DH\t\t;CARRAIGE <span class=\"hljs-keyword\">RETURN<\/span>\nLF \tEQU\t<span class=\"hljs-number\">0<\/span>AH \t\t;LINE FEED\nCTRLZ\tEQU\t<span class=\"hljs-number\">1<\/span>AH\t\t;CTRL Z\n\n\tORG\tTPA\t\t\n\nSTART:\tLD\tSP,STACK\t;SETUP STACK POINTER \t\n\nBANG:\tLD\tE,<span class=\"hljs-string\">\"#\"<\/span>\n\tCALL\tCHOUT\n\tCALL\tNEWLN\n\n\tLD\tHL,HELO\n\n\t;LOADS THE ADDR OF BEGIN OF MESG IN HL\nHELLO:\tLD\tE,(HL)\t\t;LOAD E W\/ FIRST CHAR FROM STRING \n\tLD\tA,E\t\n\tCP\t<span class=\"hljs-number\">255<\/span>\n\tJP\tZ,STRNG\n\tINC\tHL\n\tCALL\tCHOUT\n\tJP\tHELLO\t\n\nSTRNG:\tCALL\tNEWLN\n\tLD\tDE,MESG\n\tCALL\tSTROUT\n\tJP\t<span class=\"hljs-keyword\">EXIT<\/span>\n\t\n\n<span class=\"hljs-keyword\">EXIT<\/span>:\tJP\tRBOOT\t\t;<span class=\"hljs-keyword\">RETURN<\/span> TO CCP\n\n\t;STROUT - OUTPUTS A STRING WHOS ADDRESS IS IN DE REGISTER\nSTROUT:\tPUSH\tBC\t\t;SAVE REGISTERS\t\t\n\tPUSH\tDE\n\tPUSH \tHL\n\tLD\tC,WSTR\n\tCALL\tBDOS\n\tPOP\tHL\n\tPOP\tDE\t\n\tPOP\tBC\n\tRET\t\n\n\t;CHOUT - OUTPUT A CHARACTER THATS IN E REGISTER\nCHOUT:\tPUSH\tBC\t\t;SAVE REGISTERS\t\t\n\tPUSH\tDE\n\tPUSH \tHL\n\tLD\tC,WCHR\t\t;PUT WCHR IN C <span class=\"hljs-keyword\">FOR<\/span> BDOS CALL\n\tCALL\tBDOS\t\t;CALL BDOS\n\tPOP\tHL\n\tPOP\tDE\t\n\tPOP\tBC\n\tRET\n\n\t;NEWLN - DOES WHAT IT SAYS\nNEWLN:\tLD\tE,CR\t\t;NOT SURE <span class=\"hljs-keyword\">IF<\/span> WE NEED CR &amp; LF? \n\tCALL\tCHOUT\t\t;YEP, WE SEEM TO\n\tLD\tE,LF\n\tCALL\tCHOUT\n\tRET\n\nHELO:\tDB\t<span class=\"hljs-string\">\"HELLO WORLD!\"<\/span>,<span class=\"hljs-number\">255<\/span>\nMESG:\tDB\t<span class=\"hljs-string\">\"THIS IS A TEST OF A STRING OUT$\"<\/span>\n\n\tDS \t<span class=\"hljs-number\">64<\/span>\t;HOLD <span class=\"hljs-number\">64<\/span> BYTES <span class=\"hljs-keyword\">FOR<\/span> STACK\nSTACK\tDB\t<span class=\"hljs-number\">0<\/span>\t;TOP OF STACK\n\tEND\n\n\n<\/code><\/div><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"775\" height=\"507\" src=\"https:\/\/paulcarbone.com\/50days\/wp-content\/uploads\/2022\/02\/Screen-Shot-2022-02-08-at-8.24.47-PM.png\" alt=\"\" class=\"wp-image-181\" srcset=\"https:\/\/paulcarbone.com\/50days\/wp-content\/uploads\/2022\/02\/Screen-Shot-2022-02-08-at-8.24.47-PM.png 775w, https:\/\/paulcarbone.com\/50days\/wp-content\/uploads\/2022\/02\/Screen-Shot-2022-02-08-at-8.24.47-PM-300x196.png 300w, https:\/\/paulcarbone.com\/50days\/wp-content\/uploads\/2022\/02\/Screen-Shot-2022-02-08-at-8.24.47-PM-768x502.png 768w\" sizes=\"auto, (max-width: 775px) 100vw, 775px\" \/><\/figure>\n\n\n","protected":false},"excerpt":{"rendered":"<p>Yesterday proved I need to take a step back. So let me actually take my time and write a proper &#8216;Hello World&#8217; program. I&#8217;m going to do this in VS Code, since it&#8217;s just nicer to type on a 21st &hellip; <a href=\"https:\/\/paulcarbone.com\/50days\/2022\/02\/08\/day-12\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"spay_email":"","footnotes":""},"categories":[5],"tags":[],"class_list":["post-178","post","type-post","status-publish","format-standard","hentry","category-blinkinglights"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/paulcarbone.com\/50days\/wp-json\/wp\/v2\/posts\/178","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/paulcarbone.com\/50days\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/paulcarbone.com\/50days\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/paulcarbone.com\/50days\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/paulcarbone.com\/50days\/wp-json\/wp\/v2\/comments?post=178"}],"version-history":[{"count":4,"href":"https:\/\/paulcarbone.com\/50days\/wp-json\/wp\/v2\/posts\/178\/revisions"}],"predecessor-version":[{"id":185,"href":"https:\/\/paulcarbone.com\/50days\/wp-json\/wp\/v2\/posts\/178\/revisions\/185"}],"wp:attachment":[{"href":"https:\/\/paulcarbone.com\/50days\/wp-json\/wp\/v2\/media?parent=178"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/paulcarbone.com\/50days\/wp-json\/wp\/v2\/categories?post=178"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/paulcarbone.com\/50days\/wp-json\/wp\/v2\/tags?post=178"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}