{"id":32,"date":"2019-02-21T23:48:17","date_gmt":"2019-02-21T23:48:17","guid":{"rendered":"http:\/\/julien-nevo.com\/disark\/?page_id=32"},"modified":"2023-11-27T21:36:46","modified_gmt":"2023-11-27T21:36:46","slug":"examples","status":"publish","type":"page","link":"https:\/\/julien-nevo.com\/disark\/index.php\/examples\/","title":{"rendered":"Examples"},"content":{"rendered":"\n<p>Here are a few examples to show what can be done with Disark.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Classic disassembling without symbol table<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\">Without generating labels<\/h4>\n\n\n\n<p>Original code:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>    org #1000\n    ld hl,Label1\n    ld b,4\nLabel1\n    djnz Label1\n    ret<\/code><\/pre>\n\n\n\n<p>Once assembled with any assembler and disassembled with Disark:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>    ld hl,4101    ;You can also ask for hex numbers!\n    ld b,4\n    djnz $\n    ret <\/code><\/pre>\n\n\n\n<p>Nothing fancy here. Let&#8217;s continue, shall we&#8230;<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Generating labels<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>    org #1000\n    ld hl,Label1\n    ld b,4\nLabel1\n    djnz Label1\n    ret<\/code><\/pre>\n\n\n\n<p> Once assembled and disassembled with Disark using the <strong>&#8211;genLabels<\/strong> and <strong>&#8211;src16bitValuesInHex<\/strong> (to have 16 bits number in hex) options: <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>    ld hl,#1005\n    ld b,4\nlab0005 djnz lab0005         ;This label is generated.\n    ret <\/code><\/pre>\n\n\n\n<p>This is getting better&#8230;<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"mce_13\">Using a symbol table<\/h3>\n\n\n\n<p>The real power of Disark is when the original source comes with a symbol table. Most formats can be understood, and you can indicate the &#8220;column&#8221; where to find the labels and address in the symbol table, via the <strong>&#8211;labelPositionInSymbolFile<\/strong> and <strong>&#8211;addressPositionInSymbolFile<\/strong>.<\/p>\n\n\n\n<p>By using a symbol table, you can recreate the original source code from the binary!<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>        org #1000                ;Original code.\nSTART   ld bc,LABEL1\n        ld hl,$\n        ld de,LABEL1 + 3\nLABEL1  ld b,4\n        djnz LABEL1\n        jp START<\/code><\/pre>\n\n\n\n<p>The result is very close to the input! Check by yourself:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>       org #1000            ;Generated via the \"--genOrg\" option.\nSTART  ld bc,LABEL1\n       ld hl,START+3        ;Disark choses the closest label.\n       ld de,LABEL1+3\nLABEL1 ld b,4\n       djnz LABEL1\n       jp START<\/code><\/pre>\n\n\n\n<p>The command I used is:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Disark &lt;binary file to load&gt; &lt;z80 code to generate&gt; --symbolFile &lt;symbol file to load&gt; --loadAddress 0x1000 --genOrg --src16bitValuesInHex<\/code><\/pre>\n\n\n\n<p>By using the <strong>loadAddress<\/strong> option, we define the entry point. This becomes necessary so that the symbol file matches the addresses of each instructions.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Label semantics<\/h2>\n\n\n\n<p>So far the disassembled programs only consist in code. But what if you have bytes, word, even pointer areas? This is an example:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>        org #1000\n\n        ld ix,TABLE\n        \nLABEL1  ld hl,0\nLABEL2  ld de,0\nLABEL3  ld bc,0\n        \nTABLE\n        dw LABEL1       ;Oops, how to reconstruct this??\n        dw LABEL2\n        dw LABEL3\n\nLEVELDATA\n        db 1            ;Oops, how to reconstruct this??\n        db 2\n        db 3\n        \nMUSICPERIODS\n        dw 456          ;Oops, how to reconstruct this??\n        dw 147\n        dw 999<\/code><\/pre>\n\n\n\n<p>Disark, just like any disassembler, has no idea that not everything is code. Without more information, Disark will produce this:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>    org #1000\n    ld ix,TABLE\nLABEL1 ld hl,#0\nLABEL2 ld de,#0\nLABEL3 ld bc,#0             ;So far, so good.\nTABLE inc b                 ;ARG! No! This was \"db 1\"!\n    djnz MUSICPERIODS+1\n    djnz MUSICPERIODS+6\nLEVELDATA equ $+1           ;ARG! Our LevelData area is compromised too!\n    djnz LEVELDATA+2\n    ld (bc),a\n    inc bc\nMUSICPERIODS ret z          ;ARG! This is not good!\n    ld bc,#93\n    rst 32\n    inc bc\n<\/code><\/pre>\n\n\n\n<p> Ok, this is bad. But do not worry, there is a solution. Disark manages all this via <strong>Label semantics<\/strong>! The <strong>original source<\/strong> can contain <strong>labels <\/strong>indicating how to reconstruct it faithfully. These labels must have a specific format so that Disark can locate them <em>in the symbol table<\/em>. They can be added a prefix, and must be added a suffix. Some examples:<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Code region:<\/h4>\n\n\n\n<p>These are default, so you shouldn&#8217;t need to declare them.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>DisarkCodeRegionStart        a code region starts here.\nDisarkCodeRegionEnd          a code region ends here.<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Byte region:<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>DisarkByteRegionStart        a code region starts here.\nDisarkByteRegionEnd          a code region ends here.<\/code><\/pre>\n\n\n<p>Example of use:<\/p>\n\n\n<pre class=\"wp-block-code\"><code>    org #1000\n    ld hl,#1234\n    jr AFTER_STUFF\nMyDemo_DisarkByteRegionStart_Stuff   ;Declares a byte area...\n    db 1, 2, 3, 4, 5, 6, 7\n    db 8, 9, 10, 11, #ff\nMyDemo_DisarkByteRegionEnd_Stuff     ;...that ends here!\nAFTER_STUFF\n    ld de,#4567\n    ret<\/code><\/pre>\n\n\n\n<p>And the result is:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>    org #1000\n    ld hl,#1234\n    jr AFTER_STUFF\n    db 1\n    db 2\n    db 3\n    db 4\n    db 5\n    db 6\n    db 7\n    db 8\n    db 9\n    db 10\n    db 11\n    db 255\nAFTER_STUFF ld de,#4567\n    ret <\/code><\/pre>\n\n\n\n<p>YES! Now the code is perfectly regenerated! Note how the Disark marker labels have been removed from the disassembled source. They are not needed in the code anymore!<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Word region and Pointer region:<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>DisarkWordRegionStart           ;A word region starts here.\nDisarkWordRegionEnd             ;A word region ends here.\nDisarkPointerRegionStart        ;A pointer region starts here.\nDisarkPointerRegionEnd          ;A pointer region ends here.<\/code><\/pre>\n\n\n\n<p>But what is the difference between Word and Pointer region? No reference will be inferred (i.e. &#8220;guessed&#8221;) from the Word region, but they will from the Pointer region. In the example above, music periods must stay &#8220;as-is&#8221; and not converted to a pointer, else relocating the code will also modify your music periods!<\/p>\n\n\n\n<p><strong>They are many Labels you can use to add semantic to your code, <a href=\"http:\/\/julien-nevo.com\/disark\/index.php\/label-semantics\/\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\"check the list here (opens in a new tab)\">check the list here<\/a>.<\/strong><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Let&#8217;s go back to our example <\/h3>\n\n\n\n<p>By adding these labels in the original code, we can help Disark determine where is the code, and the data:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>        org #1000\n\n        ld ix,TABLE\n        \nLABEL1  ld hl,0\nLABEL2  ld de,0\nLABEL3  ld bc,0\n\nTABLE\nMyDemo_DisarkPointerRegionStart_1    ;Declares our Pointer region.\n        dw LABEL1\n        dw LABEL2\n        dw LABEL3\nMyDemo_DisarkPointerRegionEnd_1     ;The prefix and postfix must match!\n\nLEVELDATA\nMyDemo_DisarkByteRegionStart_LevelData  ;This is the Byte region.\n        db 1\n        db 2\n        db 3\nMyDemo_DisarkByteRegionEnd_LevelData\n        \nMUSICPERIODS\nMyDemo_DisarkWordRegionStart_3   ;This is our Word region.\n        dw 456\n        dw 147\n        dw 999\nMyDemo_DisarkWordRegionEnd_3<\/code><\/pre>\n\n\n\n<p>Now let&#8217;s &#8220;disark&#8221; the generated binary and&#8230;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>        org 4096\n        ld ix,TABLE\nLABEL1  ld hl,0\nLABEL2  ld de,0\nLABEL3  ld bc,0\nTABLE   dw LABEL1      ;Oh yeah! The pointers are correct!\n        dw LABEL2\n        dw LABEL3\nLEVELDATA db 1         ;Yeeepeee! The DBs are well written!\n        db 2\n        db 3\nMUSICPERIODS dw 456    ;Hurray! The Words are intact!\n        dw 147\n        dw 999\n<\/code><\/pre>\n\n\n\n<p>I guess you&#8217;ve understand how it works (if not, please contact me and I&#8217;ll try to give better examples!).<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Here are a few examples to show what can be done with Disark. Classic disassembling without symbol table Without generating labels Original code: Once assembled with any assembler and disassembled with Disark: Nothing fancy here. Let&#8217;s continue, shall we&#8230; Generating labels Once assembled and disassembled with Disark using the &#8211;genLabels and &#8211;src16bitValuesInHex (to have 16 <span class=\"spf-read-more\"><a class=\"spf-link-more\" href=\"https:\/\/julien-nevo.com\/disark\/index.php\/examples\/\" title=\"Read moreExamples\">Read more<\/a><\/span><\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-32","page","type-page","status-publish","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v25.4 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Examples - Disark<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/julien-nevo.com\/disark\/index.php\/examples\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Examples - Disark\" \/>\n<meta property=\"og:description\" content=\"Here are a few examples to show what can be done with Disark. Classic disassembling without symbol table Without generating labels Original code: Once assembled with any assembler and disassembled with Disark: Nothing fancy here. Let&#8217;s continue, shall we&#8230; Generating labels Once assembled and disassembled with Disark using the &#8211;genLabels and &#8211;src16bitValuesInHex (to have 16 Read more\" \/>\n<meta property=\"og:url\" content=\"https:\/\/julien-nevo.com\/disark\/index.php\/examples\/\" \/>\n<meta property=\"og:site_name\" content=\"Disark\" \/>\n<meta property=\"article:modified_time\" content=\"2023-11-27T21:36:46+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/julien-nevo.com\/disark\/index.php\/examples\/\",\"url\":\"https:\/\/julien-nevo.com\/disark\/index.php\/examples\/\",\"name\":\"Examples - Disark\",\"isPartOf\":{\"@id\":\"http:\/\/julien-nevo.com\/disark\/#website\"},\"datePublished\":\"2019-02-21T23:48:17+00:00\",\"dateModified\":\"2023-11-27T21:36:46+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/julien-nevo.com\/disark\/index.php\/examples\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/julien-nevo.com\/disark\/index.php\/examples\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/julien-nevo.com\/disark\/index.php\/examples\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"http:\/\/julien-nevo.com\/disark\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Examples\"}]},{\"@type\":\"WebSite\",\"@id\":\"http:\/\/julien-nevo.com\/disark\/#website\",\"url\":\"http:\/\/julien-nevo.com\/disark\/\",\"name\":\"Disark\",\"description\":\"A powerful cross-platform Z80 disassembler \/ source converter\",\"publisher\":{\"@id\":\"http:\/\/julien-nevo.com\/disark\/#\/schema\/person\/1c076d62ea698382f18b9a2a7bfddb15\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"http:\/\/julien-nevo.com\/disark\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"http:\/\/julien-nevo.com\/disark\/#\/schema\/person\/1c076d62ea698382f18b9a2a7bfddb15\",\"name\":\"Targhan\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\/\/julien-nevo.com\/disark\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/c4ecfa4cef2c920a1d2544b3025074e4ab0d1685c53b73ecdf3c803225808696?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/c4ecfa4cef2c920a1d2544b3025074e4ab0d1685c53b73ecdf3c803225808696?s=96&d=mm&r=g\",\"caption\":\"Targhan\"},\"logo\":{\"@id\":\"http:\/\/julien-nevo.com\/disark\/#\/schema\/person\/image\/\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Examples - Disark","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/julien-nevo.com\/disark\/index.php\/examples\/","og_locale":"en_US","og_type":"article","og_title":"Examples - Disark","og_description":"Here are a few examples to show what can be done with Disark. Classic disassembling without symbol table Without generating labels Original code: Once assembled with any assembler and disassembled with Disark: Nothing fancy here. Let&#8217;s continue, shall we&#8230; Generating labels Once assembled and disassembled with Disark using the &#8211;genLabels and &#8211;src16bitValuesInHex (to have 16 Read more","og_url":"https:\/\/julien-nevo.com\/disark\/index.php\/examples\/","og_site_name":"Disark","article_modified_time":"2023-11-27T21:36:46+00:00","twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/julien-nevo.com\/disark\/index.php\/examples\/","url":"https:\/\/julien-nevo.com\/disark\/index.php\/examples\/","name":"Examples - Disark","isPartOf":{"@id":"http:\/\/julien-nevo.com\/disark\/#website"},"datePublished":"2019-02-21T23:48:17+00:00","dateModified":"2023-11-27T21:36:46+00:00","breadcrumb":{"@id":"https:\/\/julien-nevo.com\/disark\/index.php\/examples\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/julien-nevo.com\/disark\/index.php\/examples\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/julien-nevo.com\/disark\/index.php\/examples\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"http:\/\/julien-nevo.com\/disark\/"},{"@type":"ListItem","position":2,"name":"Examples"}]},{"@type":"WebSite","@id":"http:\/\/julien-nevo.com\/disark\/#website","url":"http:\/\/julien-nevo.com\/disark\/","name":"Disark","description":"A powerful cross-platform Z80 disassembler \/ source converter","publisher":{"@id":"http:\/\/julien-nevo.com\/disark\/#\/schema\/person\/1c076d62ea698382f18b9a2a7bfddb15"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"http:\/\/julien-nevo.com\/disark\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"http:\/\/julien-nevo.com\/disark\/#\/schema\/person\/1c076d62ea698382f18b9a2a7bfddb15","name":"Targhan","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/julien-nevo.com\/disark\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/c4ecfa4cef2c920a1d2544b3025074e4ab0d1685c53b73ecdf3c803225808696?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/c4ecfa4cef2c920a1d2544b3025074e4ab0d1685c53b73ecdf3c803225808696?s=96&d=mm&r=g","caption":"Targhan"},"logo":{"@id":"http:\/\/julien-nevo.com\/disark\/#\/schema\/person\/image\/"}}]}},"_links":{"self":[{"href":"https:\/\/julien-nevo.com\/disark\/index.php\/wp-json\/wp\/v2\/pages\/32","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/julien-nevo.com\/disark\/index.php\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/julien-nevo.com\/disark\/index.php\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/julien-nevo.com\/disark\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/julien-nevo.com\/disark\/index.php\/wp-json\/wp\/v2\/comments?post=32"}],"version-history":[{"count":25,"href":"https:\/\/julien-nevo.com\/disark\/index.php\/wp-json\/wp\/v2\/pages\/32\/revisions"}],"predecessor-version":[{"id":121,"href":"https:\/\/julien-nevo.com\/disark\/index.php\/wp-json\/wp\/v2\/pages\/32\/revisions\/121"}],"wp:attachment":[{"href":"https:\/\/julien-nevo.com\/disark\/index.php\/wp-json\/wp\/v2\/media?parent=32"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}