Is there any special reason for STOSB to use extra segment? [closed]












2















I have read that STOSB functions like this:



ES:[DI] <-- AL


If DF = 0 increment DI else decrement DI.




  • So why STOSB doesn't change DS:[DI]?

  • Is there a special purpose for using extra segment?

  • In most string instructions we use extra segment. Why?










share|improve this question















closed as too broad by old_timer, Roman Pokrovskij, Cindy Meister, Umair, Kaushik Nayak Dec 31 '18 at 8:12


Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.























    2















    I have read that STOSB functions like this:



    ES:[DI] <-- AL


    If DF = 0 increment DI else decrement DI.




    • So why STOSB doesn't change DS:[DI]?

    • Is there a special purpose for using extra segment?

    • In most string instructions we use extra segment. Why?










    share|improve this question















    closed as too broad by old_timer, Roman Pokrovskij, Cindy Meister, Umair, Kaushik Nayak Dec 31 '18 at 8:12


    Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.





















      2












      2








      2








      I have read that STOSB functions like this:



      ES:[DI] <-- AL


      If DF = 0 increment DI else decrement DI.




      • So why STOSB doesn't change DS:[DI]?

      • Is there a special purpose for using extra segment?

      • In most string instructions we use extra segment. Why?










      share|improve this question
















      I have read that STOSB functions like this:



      ES:[DI] <-- AL


      If DF = 0 increment DI else decrement DI.




      • So why STOSB doesn't change DS:[DI]?

      • Is there a special purpose for using extra segment?

      • In most string instructions we use extra segment. Why?







      assembly x86-16






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Dec 30 '18 at 15:56









      Sep Roland

      11.9k21945




      11.9k21945










      asked Dec 29 '18 at 14:46









      oscar tabarezoscar tabarez

      475




      475




      closed as too broad by old_timer, Roman Pokrovskij, Cindy Meister, Umair, Kaushik Nayak Dec 31 '18 at 8:12


      Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.









      closed as too broad by old_timer, Roman Pokrovskij, Cindy Meister, Umair, Kaushik Nayak Dec 31 '18 at 8:12


      Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.


























          1 Answer
          1






          active

          oldest

          votes


















          5















          So why STOSB doesn't change DS:[DI]




          Because this definition would collide with the use of LODSB which already uses DS:[SI]. Using a separate segment register gives you more flexibility.




          Is there a special purpose for using extra segment?




          Yes. You can transfer bytes between segments easily while processing them. For example, you can use a LODSB loading AL from DS:[SI], modify AL and then store it to a different segment, the Extra Segment, with STOSB using ES:[DI]. In 8086 with its 16-bit segment size and a 20-bit address space this is really useful.



          Another instruction illustrating the use is the REP MOVSB instruction which copies a sequence of bytes (with its length in CX) from DS:[SI] to ES:[DI].



          (If you don't need to examine each byte as you copy it, you'd simply use rep movsb or rep movsw for better performance than lods/stos in a loop.)




          In most string instructions we use extra segment. why?




          Well, not in most, but maybe roughly in half of them. Using another segment register gives you the advantage of quick access to different segments - you are not limited to processing data only in one 64KB segment and do not have to change the DS register before each access to a different segment.



          stos and movs write es:[di], which makes sense because DI is the "destination index" register.



          cmps and scas read from es:[di], which is maybe surprising for scas because it only has one memory operand so you might expect it to read from ds:[si] like lods. Especially because SCASB sets flags from AL - [mem], not the other way around, so it's like a cmp where memory is the right operand (source), not left (destination). Like cmp al, es:[di].



          Perhaps the architect of the 8086's instruction set imagined a use-case of a loop that does lods and scas to implement strcmp between segments.






          share|improve this answer


























          • For most of the string instructions, ES:DI (DI -> destination index) is the store address, with SCASB/W being the exception that is uses ES:DI to scan (read) memory for a matching byte / word (in 16 bit mode).

            – rcgldr
            Dec 29 '18 at 15:29











          • If your length is ECX (not just CX), your addresses will also be 32-bit DS:[ESI], not SI. There might be a combination of prefixes which could achieve 16-bit address-size and 32-bit counter size in some mode, but I'm not sure. It certainly wouldn't be normal, though.

            – Peter Cordes
            Dec 30 '18 at 8:49




















          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          5















          So why STOSB doesn't change DS:[DI]




          Because this definition would collide with the use of LODSB which already uses DS:[SI]. Using a separate segment register gives you more flexibility.




          Is there a special purpose for using extra segment?




          Yes. You can transfer bytes between segments easily while processing them. For example, you can use a LODSB loading AL from DS:[SI], modify AL and then store it to a different segment, the Extra Segment, with STOSB using ES:[DI]. In 8086 with its 16-bit segment size and a 20-bit address space this is really useful.



          Another instruction illustrating the use is the REP MOVSB instruction which copies a sequence of bytes (with its length in CX) from DS:[SI] to ES:[DI].



          (If you don't need to examine each byte as you copy it, you'd simply use rep movsb or rep movsw for better performance than lods/stos in a loop.)




          In most string instructions we use extra segment. why?




          Well, not in most, but maybe roughly in half of them. Using another segment register gives you the advantage of quick access to different segments - you are not limited to processing data only in one 64KB segment and do not have to change the DS register before each access to a different segment.



          stos and movs write es:[di], which makes sense because DI is the "destination index" register.



          cmps and scas read from es:[di], which is maybe surprising for scas because it only has one memory operand so you might expect it to read from ds:[si] like lods. Especially because SCASB sets flags from AL - [mem], not the other way around, so it's like a cmp where memory is the right operand (source), not left (destination). Like cmp al, es:[di].



          Perhaps the architect of the 8086's instruction set imagined a use-case of a loop that does lods and scas to implement strcmp between segments.






          share|improve this answer


























          • For most of the string instructions, ES:DI (DI -> destination index) is the store address, with SCASB/W being the exception that is uses ES:DI to scan (read) memory for a matching byte / word (in 16 bit mode).

            – rcgldr
            Dec 29 '18 at 15:29











          • If your length is ECX (not just CX), your addresses will also be 32-bit DS:[ESI], not SI. There might be a combination of prefixes which could achieve 16-bit address-size and 32-bit counter size in some mode, but I'm not sure. It certainly wouldn't be normal, though.

            – Peter Cordes
            Dec 30 '18 at 8:49


















          5















          So why STOSB doesn't change DS:[DI]




          Because this definition would collide with the use of LODSB which already uses DS:[SI]. Using a separate segment register gives you more flexibility.




          Is there a special purpose for using extra segment?




          Yes. You can transfer bytes between segments easily while processing them. For example, you can use a LODSB loading AL from DS:[SI], modify AL and then store it to a different segment, the Extra Segment, with STOSB using ES:[DI]. In 8086 with its 16-bit segment size and a 20-bit address space this is really useful.



          Another instruction illustrating the use is the REP MOVSB instruction which copies a sequence of bytes (with its length in CX) from DS:[SI] to ES:[DI].



          (If you don't need to examine each byte as you copy it, you'd simply use rep movsb or rep movsw for better performance than lods/stos in a loop.)




          In most string instructions we use extra segment. why?




          Well, not in most, but maybe roughly in half of them. Using another segment register gives you the advantage of quick access to different segments - you are not limited to processing data only in one 64KB segment and do not have to change the DS register before each access to a different segment.



          stos and movs write es:[di], which makes sense because DI is the "destination index" register.



          cmps and scas read from es:[di], which is maybe surprising for scas because it only has one memory operand so you might expect it to read from ds:[si] like lods. Especially because SCASB sets flags from AL - [mem], not the other way around, so it's like a cmp where memory is the right operand (source), not left (destination). Like cmp al, es:[di].



          Perhaps the architect of the 8086's instruction set imagined a use-case of a loop that does lods and scas to implement strcmp between segments.






          share|improve this answer


























          • For most of the string instructions, ES:DI (DI -> destination index) is the store address, with SCASB/W being the exception that is uses ES:DI to scan (read) memory for a matching byte / word (in 16 bit mode).

            – rcgldr
            Dec 29 '18 at 15:29











          • If your length is ECX (not just CX), your addresses will also be 32-bit DS:[ESI], not SI. There might be a combination of prefixes which could achieve 16-bit address-size and 32-bit counter size in some mode, but I'm not sure. It certainly wouldn't be normal, though.

            – Peter Cordes
            Dec 30 '18 at 8:49
















          5












          5








          5








          So why STOSB doesn't change DS:[DI]




          Because this definition would collide with the use of LODSB which already uses DS:[SI]. Using a separate segment register gives you more flexibility.




          Is there a special purpose for using extra segment?




          Yes. You can transfer bytes between segments easily while processing them. For example, you can use a LODSB loading AL from DS:[SI], modify AL and then store it to a different segment, the Extra Segment, with STOSB using ES:[DI]. In 8086 with its 16-bit segment size and a 20-bit address space this is really useful.



          Another instruction illustrating the use is the REP MOVSB instruction which copies a sequence of bytes (with its length in CX) from DS:[SI] to ES:[DI].



          (If you don't need to examine each byte as you copy it, you'd simply use rep movsb or rep movsw for better performance than lods/stos in a loop.)




          In most string instructions we use extra segment. why?




          Well, not in most, but maybe roughly in half of them. Using another segment register gives you the advantage of quick access to different segments - you are not limited to processing data only in one 64KB segment and do not have to change the DS register before each access to a different segment.



          stos and movs write es:[di], which makes sense because DI is the "destination index" register.



          cmps and scas read from es:[di], which is maybe surprising for scas because it only has one memory operand so you might expect it to read from ds:[si] like lods. Especially because SCASB sets flags from AL - [mem], not the other way around, so it's like a cmp where memory is the right operand (source), not left (destination). Like cmp al, es:[di].



          Perhaps the architect of the 8086's instruction set imagined a use-case of a loop that does lods and scas to implement strcmp between segments.






          share|improve this answer
















          So why STOSB doesn't change DS:[DI]




          Because this definition would collide with the use of LODSB which already uses DS:[SI]. Using a separate segment register gives you more flexibility.




          Is there a special purpose for using extra segment?




          Yes. You can transfer bytes between segments easily while processing them. For example, you can use a LODSB loading AL from DS:[SI], modify AL and then store it to a different segment, the Extra Segment, with STOSB using ES:[DI]. In 8086 with its 16-bit segment size and a 20-bit address space this is really useful.



          Another instruction illustrating the use is the REP MOVSB instruction which copies a sequence of bytes (with its length in CX) from DS:[SI] to ES:[DI].



          (If you don't need to examine each byte as you copy it, you'd simply use rep movsb or rep movsw for better performance than lods/stos in a loop.)




          In most string instructions we use extra segment. why?




          Well, not in most, but maybe roughly in half of them. Using another segment register gives you the advantage of quick access to different segments - you are not limited to processing data only in one 64KB segment and do not have to change the DS register before each access to a different segment.



          stos and movs write es:[di], which makes sense because DI is the "destination index" register.



          cmps and scas read from es:[di], which is maybe surprising for scas because it only has one memory operand so you might expect it to read from ds:[si] like lods. Especially because SCASB sets flags from AL - [mem], not the other way around, so it's like a cmp where memory is the right operand (source), not left (destination). Like cmp al, es:[di].



          Perhaps the architect of the 8086's instruction set imagined a use-case of a loop that does lods and scas to implement strcmp between segments.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Dec 30 '18 at 15:49









          Sep Roland

          11.9k21945




          11.9k21945










          answered Dec 29 '18 at 15:06









          zx485zx485

          14k122947




          14k122947













          • For most of the string instructions, ES:DI (DI -> destination index) is the store address, with SCASB/W being the exception that is uses ES:DI to scan (read) memory for a matching byte / word (in 16 bit mode).

            – rcgldr
            Dec 29 '18 at 15:29











          • If your length is ECX (not just CX), your addresses will also be 32-bit DS:[ESI], not SI. There might be a combination of prefixes which could achieve 16-bit address-size and 32-bit counter size in some mode, but I'm not sure. It certainly wouldn't be normal, though.

            – Peter Cordes
            Dec 30 '18 at 8:49





















          • For most of the string instructions, ES:DI (DI -> destination index) is the store address, with SCASB/W being the exception that is uses ES:DI to scan (read) memory for a matching byte / word (in 16 bit mode).

            – rcgldr
            Dec 29 '18 at 15:29











          • If your length is ECX (not just CX), your addresses will also be 32-bit DS:[ESI], not SI. There might be a combination of prefixes which could achieve 16-bit address-size and 32-bit counter size in some mode, but I'm not sure. It certainly wouldn't be normal, though.

            – Peter Cordes
            Dec 30 '18 at 8:49



















          For most of the string instructions, ES:DI (DI -> destination index) is the store address, with SCASB/W being the exception that is uses ES:DI to scan (read) memory for a matching byte / word (in 16 bit mode).

          – rcgldr
          Dec 29 '18 at 15:29





          For most of the string instructions, ES:DI (DI -> destination index) is the store address, with SCASB/W being the exception that is uses ES:DI to scan (read) memory for a matching byte / word (in 16 bit mode).

          – rcgldr
          Dec 29 '18 at 15:29













          If your length is ECX (not just CX), your addresses will also be 32-bit DS:[ESI], not SI. There might be a combination of prefixes which could achieve 16-bit address-size and 32-bit counter size in some mode, but I'm not sure. It certainly wouldn't be normal, though.

          – Peter Cordes
          Dec 30 '18 at 8:49







          If your length is ECX (not just CX), your addresses will also be 32-bit DS:[ESI], not SI. There might be a combination of prefixes which could achieve 16-bit address-size and 32-bit counter size in some mode, but I'm not sure. It certainly wouldn't be normal, though.

          – Peter Cordes
          Dec 30 '18 at 8:49





          Popular posts from this blog

          Monofisismo

          Angular Downloading a file using contenturl with Basic Authentication

          Olmecas