{"id":2298,"date":"2023-02-11T04:22:40","date_gmt":"2023-02-11T04:22:40","guid":{"rendered":"https:\/\/usemynotes.com\/?p=2298"},"modified":"2025-11-13T22:52:59","modified_gmt":"2025-11-13T17:22:59","slug":"subroutine-in-8085-microprocessor","status":"publish","type":"post","link":"https:\/\/usemynotes.com\/subroutine-in-8085-microprocessor\/","title":{"rendered":"Subroutine in 8085 Microprocessor"},"content":{"rendered":"<p>In this course, we will study the subroutine in 8085 Microprocessor, subroutine nesting, its uses, and the difference between function and subroutine.<\/p>\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_80 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 eztoc-toggle-hide-by-default' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/usemynotes.com\/subroutine-in-8085-microprocessor\/#Subroutine_in_8085_Microprocessor\" >Subroutine in 8085 Microprocessor<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/usemynotes.com\/subroutine-in-8085-microprocessor\/#There_are_two_instructions_in_8085_that_deal_with_subroutines\" >There are two instructions in 8085 that deal with subroutines:<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/usemynotes.com\/subroutine-in-8085-microprocessor\/#The_CALL_function\" >The CALL function<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/usemynotes.com\/subroutine-in-8085-microprocessor\/#The_RET_function\" >The RET function<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/usemynotes.com\/subroutine-in-8085-microprocessor\/#How_do_we_pass_the_data_to_the_Subroutine_in_8085_Microprocessor\" >How do we pass the data to the Subroutine in 8085 Microprocessor?<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/usemynotes.com\/subroutine-in-8085-microprocessor\/#Call_by_Reference_Subroutine_in_8085_Microprocessor\" >Call by Reference Subroutine in 8085 Microprocessor<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/usemynotes.com\/subroutine-in-8085-microprocessor\/#Call_by_value_Subroutine_in_8085_Microprocessor\" >Call by value Subroutine in 8085 Microprocessor<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/usemynotes.com\/subroutine-in-8085-microprocessor\/#What_is_subroutine_nesting_in_8085_Microprocessor\" >What is subroutine nesting in 8085 Microprocessor?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/usemynotes.com\/subroutine-in-8085-microprocessor\/#What_is_the_use_of_Subroutine_8085_Microprocessor\" >What is the use of Subroutine 8085 Microprocessor?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/usemynotes.com\/subroutine-in-8085-microprocessor\/#What_is_the_difference_between_function_and_subroutine\" >What is the difference between function and subroutine?<\/a><\/li><\/ul><\/nav><\/div>\n<h2><span class=\"ez-toc-section\" id=\"Subroutine_in_8085_Microprocessor\"><\/span>Subroutine in 8085 Microprocessor<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>A Subroutine in 8085 Microprocessor is a function and is used to reduce the size of the program. Instead of writing the same code, again and again, we make the code a function and this reduces the size of the program. Only one copy of the code is stored in the memory. Whenever the code is required we can write a subroutine instruction that will call the subroutine. A subroutine can exist anywhere in the code.<\/p>\n<p><img decoding=\"async\" class=\"alignnone wp-image-2301 size-full\" src=\"https:\/\/usemynotes.com\/wp-content\/uploads\/2023\/02\/Subroutine-in-8085-Microprocessor.jpg\" alt=\"Subroutine in 8085 Microprocessor\" width=\"1200\" height=\"850\" title=\"\" srcset=\"https:\/\/usemynotes.com\/wp-content\/uploads\/2023\/02\/Subroutine-in-8085-Microprocessor.jpg 1200w, https:\/\/usemynotes.com\/wp-content\/uploads\/2023\/02\/Subroutine-in-8085-Microprocessor-300x213.jpg 300w, https:\/\/usemynotes.com\/wp-content\/uploads\/2023\/02\/Subroutine-in-8085-Microprocessor-1024x725.jpg 1024w, https:\/\/usemynotes.com\/wp-content\/uploads\/2023\/02\/Subroutine-in-8085-Microprocessor-768x544.jpg 768w, https:\/\/usemynotes.com\/wp-content\/uploads\/2023\/02\/Subroutine-in-8085-Microprocessor-150x106.jpg 150w, https:\/\/usemynotes.com\/wp-content\/uploads\/2023\/02\/Subroutine-in-8085-Microprocessor-696x493.jpg 696w, https:\/\/usemynotes.com\/wp-content\/uploads\/2023\/02\/Subroutine-in-8085-Microprocessor-1068x757.jpg 1068w, https:\/\/usemynotes.com\/wp-content\/uploads\/2023\/02\/Subroutine-in-8085-Microprocessor-593x420.jpg 593w, https:\/\/usemynotes.com\/wp-content\/uploads\/2023\/02\/Subroutine-in-8085-Microprocessor-100x70.jpg 100w\" sizes=\"(max-width: 1200px) 100vw, 1200px\" \/><\/p>\n<p>Whenever a Subroutine in 8085 Microprocessor instruction is encountered in the program the code is executed and then the next instruction in the program is executed. Great care should be taken while returning the subroutine because it can be called from various locations of memory.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"There_are_two_instructions_in_8085_that_deal_with_subroutines\"><\/span>There are two instructions in 8085 that deal with subroutines:<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<ul>\n<li>The CALL instruction in 8085 Microprocessor is used for redirecting the program execution to a subroutine.<\/li>\n<li>The RET instruction in 8085 Microprocessor is used for returning the execution to the calling routine.<\/li>\n<\/ul>\n<h3><span class=\"ez-toc-section\" id=\"The_CALL_function\"><\/span>The CALL function<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>\n<li>The <a href=\"https:\/\/usemynotes.com\/what-is-a-microprocessor\/\">microprocessor<\/a> reads the subroutine address from the following two memory locations and stores the higher order of 8 bits of the address in the W register and stores the lower order of 8 bits of address in the Z register.<\/li>\n<li>The addresses of the instruction immediately following the call are pushed onto the stack.<\/li>\n<li>Loads the program counter with the 16-bit address supplied with the call instruction from WZ registers.<\/li>\n<\/ol>\n<\/li>\n<\/ol>\n<h3><span class=\"ez-toc-section\" id=\"The_RET_function\"><\/span>The RET function<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<ol>\n<li>It retrieves the return address from the top of the stack.<\/li>\n<li>Loads the program counter with the return address.<\/li>\n<\/ol>\n<h2><span class=\"ez-toc-section\" id=\"How_do_we_pass_the_data_to_the_Subroutine_in_8085_Microprocessor\"><\/span>How do we pass the data to the Subroutine in 8085 Microprocessor?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Data in the subroutine can be passed in two ways: call by value and call by reference.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Call_by_Reference_Subroutine_in_8085_Microprocessor\"><\/span>Call by Reference Subroutine in 8085 Microprocessor<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>The subroutine uses the value from the register, the data is stored in one of the registers by the calling program. The register value gets modified within the subroutine. Then these modifications can be transferred back to the calling program upon returning from the subroutine.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Call_by_value_Subroutine_in_8085_Microprocessor\"><\/span>Call by value Subroutine in 8085 Microprocessor<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>The subroutine first pushes register values in the stack and after using the registers, the subroutine pops the previous values of the registers from the stack while exiting the subroutine. The data is stored in one of the registers. The original values are restored before execution returns to the calling program.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"What_is_subroutine_nesting_in_8085_Microprocessor\"><\/span>What is subroutine nesting in 8085 Microprocessor?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Subroutine nesting <a href=\"https:\/\/usemynotes.com\/microprocessor\/\">8085 Microprocessor<\/a> is calling a subroutine from another subroutine call. It is like calling one function and that function calls another function by itself.<\/p>\n<h2><img decoding=\"async\" class=\"aligncenter wp-image-2302 size-full\" src=\"https:\/\/usemynotes.com\/wp-content\/uploads\/2023\/02\/subroutine-nesting.png\" alt=\"Subroutine nesting in 8085 Microprocessor\" width=\"586\" height=\"295\" title=\"\" srcset=\"https:\/\/usemynotes.com\/wp-content\/uploads\/2023\/02\/subroutine-nesting.png 586w, https:\/\/usemynotes.com\/wp-content\/uploads\/2023\/02\/subroutine-nesting-300x151.png 300w, https:\/\/usemynotes.com\/wp-content\/uploads\/2023\/02\/subroutine-nesting-150x76.png 150w\" sizes=\"(max-width: 586px) 100vw, 586px\" \/><\/h2>\n<h2><span class=\"ez-toc-section\" id=\"What_is_the_use_of_Subroutine_8085_Microprocessor\"><\/span>What is the use of Subroutine 8085 Microprocessor?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<ul>\n<li>Repetition of instructions can be avoided<\/li>\n<li>The efficiency of the program is improved<\/li>\n<li>Size is reduced<\/li>\n<\/ul>\n<h2><span class=\"ez-toc-section\" id=\"What_is_the_difference_between_function_and_subroutine\"><\/span>What is the difference between function and subroutine?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<table class=\"table table-bordered table-striped\">\n<thead>\n<tr>\n<th>FUNCTION<\/th>\n<th>SUBROUTINE<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>A function always returns a value.<\/td>\n<td>A subroutine performs a set of tasks and does not return a value.<\/td>\n<\/tr>\n<tr>\n<td>They can be used as formulas in the spreadsheet.<\/td>\n<td>They can not be used directly as formulas in the spreadsheet.<\/td>\n<\/tr>\n<tr>\n<td>They are called by using a variable<\/td>\n<td>They are called by using the call function after their declaration<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>Thanks for learning <strong>Subroutine in 8085 Microprocessor<\/strong> with me.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this course, we will study the subroutine in 8085 Microprocessor, subroutine nesting, its uses, and the difference between function and subroutine. Subroutine in 8085 Microprocessor A Subroutine in 8085 Microprocessor is a function and is used to reduce the size of the program. Instead of writing the same code, again and again, we make [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":2301,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[184],"tags":[],"class_list":{"0":"post-2298","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-microprocessor"},"_links":{"self":[{"href":"https:\/\/usemynotes.com\/wp-json\/wp\/v2\/posts\/2298","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/usemynotes.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/usemynotes.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/usemynotes.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/usemynotes.com\/wp-json\/wp\/v2\/comments?post=2298"}],"version-history":[{"count":1,"href":"https:\/\/usemynotes.com\/wp-json\/wp\/v2\/posts\/2298\/revisions"}],"predecessor-version":[{"id":9164,"href":"https:\/\/usemynotes.com\/wp-json\/wp\/v2\/posts\/2298\/revisions\/9164"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/usemynotes.com\/wp-json\/wp\/v2\/media\/2301"}],"wp:attachment":[{"href":"https:\/\/usemynotes.com\/wp-json\/wp\/v2\/media?parent=2298"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/usemynotes.com\/wp-json\/wp\/v2\/categories?post=2298"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/usemynotes.com\/wp-json\/wp\/v2\/tags?post=2298"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}