{"id":3582,"date":"2025-04-18T12:41:02","date_gmt":"2025-04-18T12:41:02","guid":{"rendered":"https:\/\/webprojects.cloud\/wordpress\/splatco\/?post_type=spl_knowledgebase&#038;p=3582"},"modified":"2025-06-10T11:56:58","modified_gmt":"2025-06-10T11:56:58","slug":"example-advanced-combining-semaphores-and-branch-instructions","status":"publish","type":"spl_knowledgebase","link":"https:\/\/webprojects.cloud\/wordpress\/splatco\/knowledgebase\/tutorials-application-notes-and-white-papers\/tutorial-semaphores\/semaphores-programming-examples\/example-advanced-combining-semaphores-and-branch-instructions\/","title":{"rendered":"Example (Advanced): Combining semaphores and Branch instructions"},"content":{"rendered":"\n<p>This example follows on from the previous one, to give you an interesting way of testing and branching out depending on several semaphores. Imagine you have 3 semaphores, semA, semB and semC. These may represent inputs or the results of previous calculations. You now need to do one of several things depending on the semaphores. The following table summarizes what your program must do:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><th>C<\/th><th>B<\/th><th>A<\/th><th>GoTo &#8230;<\/th><th>N<\/th><\/tr><tr><td>0<\/td><td>0<\/td><td>0<\/td><td>DoIT<\/td><td>0<\/td><\/tr><tr><td>0<\/td><td>0<\/td><td>1<\/td><td>CanIt<\/td><td>1<\/td><\/tr><tr><td>0<\/td><td>1<\/td><td>0<\/td><td>GoAway<\/td><td>2<\/td><\/tr><tr><td>0<\/td><td>1<\/td><td>1<\/td><td>DoIt<\/td><td>3<\/td><\/tr><tr><td>1<\/td><td>0<\/td><td>0<\/td><td>GoAway<\/td><td>4<\/td><\/tr><tr><td>1<\/td><td>0<\/td><td>1<\/td><td>CanIt<\/td><td>5<\/td><\/tr><tr><td>1<\/td><td>1<\/td><td>0<\/td><td>OhDear<\/td><td>6<\/td><\/tr><tr><td>1<\/td><td>1<\/td><td>1<\/td><td>Oopsy<\/td><td>7<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>By careful planning we locate the 3 semaphores in bits 0, 1 and 2 of a single byte MySems. Here are the directives that define them:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><br>MySems    defBYTE<br>semA      sEQU       0<br>semB      sEQU       1<br>semC      sEQU       2<br><\/pre>\n\n\n\n<p>If we interpret those 3 bits as a binary number, they can be taken as a number N between 0 and 7 (i.e. 8 numbers). This represents exactly the 8 possible permutations of 3 semaphores. If you are unfamiliar with binary numbering you can find plenty of&nbsp;<a href=\"http:\/\/www.google.com\/search?q=binary+number+system&amp;hl=en&amp;lr=&amp;ie=UTF-8&amp;start=10&amp;sa=N\">information online<\/a>.<\/p>\n\n\n\n<p>The following code will implement the above table in a compact Branch\/Target structure:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><br>   Recall      MySems<br>   LoadX       %00000111  ;Mask to select bits 0-2<br>   AndM                   ;Select the 3 semaphores<br>   <a href=\"https:\/\/webprojects.cloud\/wordpress\/splatco\/knowledgebase\/programming-reference\/instructions-arranged-by-function\/goto-gosub-and-related-instructions\/branch\/\">Branch<br><\/a>   <a href=\"https:\/\/webprojects.cloud\/wordpress\/splatco\/knowledgebase\/programming-reference\/instructions-arranged-by-function\/goto-gosub-and-related-instructions\/target-llll\/\">Target<\/a>      DoIt       ;N=0<br>   Target      CanIt      ;N=1<br>   Target      GoAway     ;N=2<br>   Target      DoIt       ;N=3<br>   Target      GoAway     ;N=4<br>   Target      CanIt      ;N=5<br>   Target      OhDear     ;N=6<br>   Target      Oopsy      ;N=7<br><\/pre>\n\n\n\n<p>This code is both compact and very easy to maintain.<\/p>\n\n\n\n<p>Exercise 1: Write the code to perform the same function without using a Branch\/Target table.<\/p>\n\n\n\n<p>Exercise 2: Modify the Branch\/Target table so the program goes to Oopsy whenever A and B are both on.<\/p>\n\n\n\n<p>Exercise 3: Modify the program in exercise 1 so it goes to Oopsy whenever A and B are both on.<\/p>\n\n\n\n<p>For those of you with a chip level design bent, this method is really the same idea as using a 1-of-8 (74HC138) or a 1-of-16 decoder chip (74HC154) to generate boolean equations.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This example follows on from the previous one, to give you an interesting way of testing and branching out depending on several semaphores. Imagine you&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":3578,"menu_order":3,"template":"","class_list":["post-3582","spl_knowledgebase","type-spl_knowledgebase","status-publish","hentry"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v25.6 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Example (Advanced): Combining semaphores and Branch instructions - SPLat Controls<\/title>\n<meta name=\"robots\" content=\"noindex, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Example (Advanced): Combining semaphores and Branch instructions - SPLat Controls\" \/>\n<meta property=\"og:description\" content=\"This example follows on from the previous one, to give you an interesting way of testing and branching out depending on several semaphores. Imagine you...\" \/>\n<meta property=\"og:url\" content=\"https:\/\/webprojects.cloud\/wordpress\/splatco\/knowledgebase\/tutorials-application-notes-and-white-papers\/tutorial-semaphores\/semaphores-programming-examples\/example-advanced-combining-semaphores-and-branch-instructions\/\" \/>\n<meta property=\"og:site_name\" content=\"SPLat Controls\" \/>\n<meta property=\"article:modified_time\" content=\"2025-06-10T11:56:58+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=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/webprojects.cloud\/wordpress\/splatco\/knowledgebase\/tutorials-application-notes-and-white-papers\/tutorial-semaphores\/semaphores-programming-examples\/example-advanced-combining-semaphores-and-branch-instructions\/\",\"url\":\"https:\/\/webprojects.cloud\/wordpress\/splatco\/knowledgebase\/tutorials-application-notes-and-white-papers\/tutorial-semaphores\/semaphores-programming-examples\/example-advanced-combining-semaphores-and-branch-instructions\/\",\"name\":\"Example (Advanced): Combining semaphores and Branch instructions - SPLat Controls\",\"isPartOf\":{\"@id\":\"https:\/\/webprojects.cloud\/wordpress\/splatco\/#website\"},\"datePublished\":\"2025-04-18T12:41:02+00:00\",\"dateModified\":\"2025-06-10T11:56:58+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/webprojects.cloud\/wordpress\/splatco\/knowledgebase\/tutorials-application-notes-and-white-papers\/tutorial-semaphores\/semaphores-programming-examples\/example-advanced-combining-semaphores-and-branch-instructions\/#breadcrumb\"},\"inLanguage\":\"en-AU\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/webprojects.cloud\/wordpress\/splatco\/knowledgebase\/tutorials-application-notes-and-white-papers\/tutorial-semaphores\/semaphores-programming-examples\/example-advanced-combining-semaphores-and-branch-instructions\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/webprojects.cloud\/wordpress\/splatco\/knowledgebase\/tutorials-application-notes-and-white-papers\/tutorial-semaphores\/semaphores-programming-examples\/example-advanced-combining-semaphores-and-branch-instructions\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/webprojects.cloud\/wordpress\/splatco\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Tutorials, application notes and white papers\",\"item\":\"https:\/\/webprojects.cloud\/wordpress\/splatco\/knowledgebase\/tutorials-application-notes-and-white-papers\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Tutorial: Semaphores\",\"item\":\"https:\/\/webprojects.cloud\/wordpress\/splatco\/knowledgebase\/tutorials-application-notes-and-white-papers\/tutorial-semaphores\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Semaphores: Programming examples\",\"item\":\"https:\/\/webprojects.cloud\/wordpress\/splatco\/knowledgebase\/tutorials-application-notes-and-white-papers\/tutorial-semaphores\/semaphores-programming-examples\/\"},{\"@type\":\"ListItem\",\"position\":5,\"name\":\"Example (Advanced): Combining semaphores and Branch instructions\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/webprojects.cloud\/wordpress\/splatco\/#website\",\"url\":\"https:\/\/webprojects.cloud\/wordpress\/splatco\/\",\"name\":\"SPLat Controls\",\"description\":\"OEM Embedded Machine Controllers\",\"publisher\":{\"@id\":\"https:\/\/webprojects.cloud\/wordpress\/splatco\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/webprojects.cloud\/wordpress\/splatco\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-AU\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/webprojects.cloud\/wordpress\/splatco\/#organization\",\"name\":\"SPLat Controls\",\"url\":\"https:\/\/webprojects.cloud\/wordpress\/splatco\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-AU\",\"@id\":\"https:\/\/webprojects.cloud\/wordpress\/splatco\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/webprojects.cloud\/wordpress\/splatco\/wp-content\/uploads\/2024\/10\/logo.svg\",\"contentUrl\":\"https:\/\/webprojects.cloud\/wordpress\/splatco\/wp-content\/uploads\/2024\/10\/logo.svg\",\"caption\":\"SPLat Controls\"},\"image\":{\"@id\":\"https:\/\/webprojects.cloud\/wordpress\/splatco\/#\/schema\/logo\/image\/\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Example (Advanced): Combining semaphores and Branch instructions - SPLat Controls","robots":{"index":"noindex","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"og_locale":"en_US","og_type":"article","og_title":"Example (Advanced): Combining semaphores and Branch instructions - SPLat Controls","og_description":"This example follows on from the previous one, to give you an interesting way of testing and branching out depending on several semaphores. Imagine you...","og_url":"https:\/\/webprojects.cloud\/wordpress\/splatco\/knowledgebase\/tutorials-application-notes-and-white-papers\/tutorial-semaphores\/semaphores-programming-examples\/example-advanced-combining-semaphores-and-branch-instructions\/","og_site_name":"SPLat Controls","article_modified_time":"2025-06-10T11:56:58+00:00","twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/webprojects.cloud\/wordpress\/splatco\/knowledgebase\/tutorials-application-notes-and-white-papers\/tutorial-semaphores\/semaphores-programming-examples\/example-advanced-combining-semaphores-and-branch-instructions\/","url":"https:\/\/webprojects.cloud\/wordpress\/splatco\/knowledgebase\/tutorials-application-notes-and-white-papers\/tutorial-semaphores\/semaphores-programming-examples\/example-advanced-combining-semaphores-and-branch-instructions\/","name":"Example (Advanced): Combining semaphores and Branch instructions - SPLat Controls","isPartOf":{"@id":"https:\/\/webprojects.cloud\/wordpress\/splatco\/#website"},"datePublished":"2025-04-18T12:41:02+00:00","dateModified":"2025-06-10T11:56:58+00:00","breadcrumb":{"@id":"https:\/\/webprojects.cloud\/wordpress\/splatco\/knowledgebase\/tutorials-application-notes-and-white-papers\/tutorial-semaphores\/semaphores-programming-examples\/example-advanced-combining-semaphores-and-branch-instructions\/#breadcrumb"},"inLanguage":"en-AU","potentialAction":[{"@type":"ReadAction","target":["https:\/\/webprojects.cloud\/wordpress\/splatco\/knowledgebase\/tutorials-application-notes-and-white-papers\/tutorial-semaphores\/semaphores-programming-examples\/example-advanced-combining-semaphores-and-branch-instructions\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/webprojects.cloud\/wordpress\/splatco\/knowledgebase\/tutorials-application-notes-and-white-papers\/tutorial-semaphores\/semaphores-programming-examples\/example-advanced-combining-semaphores-and-branch-instructions\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/webprojects.cloud\/wordpress\/splatco\/"},{"@type":"ListItem","position":2,"name":"Tutorials, application notes and white papers","item":"https:\/\/webprojects.cloud\/wordpress\/splatco\/knowledgebase\/tutorials-application-notes-and-white-papers\/"},{"@type":"ListItem","position":3,"name":"Tutorial: Semaphores","item":"https:\/\/webprojects.cloud\/wordpress\/splatco\/knowledgebase\/tutorials-application-notes-and-white-papers\/tutorial-semaphores\/"},{"@type":"ListItem","position":4,"name":"Semaphores: Programming examples","item":"https:\/\/webprojects.cloud\/wordpress\/splatco\/knowledgebase\/tutorials-application-notes-and-white-papers\/tutorial-semaphores\/semaphores-programming-examples\/"},{"@type":"ListItem","position":5,"name":"Example (Advanced): Combining semaphores and Branch instructions"}]},{"@type":"WebSite","@id":"https:\/\/webprojects.cloud\/wordpress\/splatco\/#website","url":"https:\/\/webprojects.cloud\/wordpress\/splatco\/","name":"SPLat Controls","description":"OEM Embedded Machine Controllers","publisher":{"@id":"https:\/\/webprojects.cloud\/wordpress\/splatco\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/webprojects.cloud\/wordpress\/splatco\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-AU"},{"@type":"Organization","@id":"https:\/\/webprojects.cloud\/wordpress\/splatco\/#organization","name":"SPLat Controls","url":"https:\/\/webprojects.cloud\/wordpress\/splatco\/","logo":{"@type":"ImageObject","inLanguage":"en-AU","@id":"https:\/\/webprojects.cloud\/wordpress\/splatco\/#\/schema\/logo\/image\/","url":"https:\/\/webprojects.cloud\/wordpress\/splatco\/wp-content\/uploads\/2024\/10\/logo.svg","contentUrl":"https:\/\/webprojects.cloud\/wordpress\/splatco\/wp-content\/uploads\/2024\/10\/logo.svg","caption":"SPLat Controls"},"image":{"@id":"https:\/\/webprojects.cloud\/wordpress\/splatco\/#\/schema\/logo\/image\/"}}]}},"_links":{"self":[{"href":"https:\/\/webprojects.cloud\/wordpress\/splatco\/wp-json\/wp\/v2\/spl_knowledgebase\/3582","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/webprojects.cloud\/wordpress\/splatco\/wp-json\/wp\/v2\/spl_knowledgebase"}],"about":[{"href":"https:\/\/webprojects.cloud\/wordpress\/splatco\/wp-json\/wp\/v2\/types\/spl_knowledgebase"}],"author":[{"embeddable":true,"href":"https:\/\/webprojects.cloud\/wordpress\/splatco\/wp-json\/wp\/v2\/users\/1"}],"up":[{"embeddable":true,"href":"https:\/\/webprojects.cloud\/wordpress\/splatco\/wp-json\/wp\/v2\/spl_knowledgebase\/3578"}],"wp:attachment":[{"href":"https:\/\/webprojects.cloud\/wordpress\/splatco\/wp-json\/wp\/v2\/media?parent=3582"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}