I want to swap the position of two bits. How to do this? The Next CEO of Stack OverflowWhat are the segment and offset in real mode memory addressing?How to right rotate a 64-bit value efficiently in ARM7 assembler?IA-32e 64-bit IDT Gate DescriptorBase pointer and stack pointerx86 - segmentation in protected mode serves what purpose?conceptual help understanding OFFSET Function and the ways in which this program outputsReplacing a 32-bit loop counter with 64-bit introduces crazy performance deviationsAccessing the Program Segment PrefixWhat happens to instruction pointers when address overrides are used to target a smaller address space?Verify that in a range of bits only one is on

Indicator light circuit

Why do professional authors make "consistency" mistakes? And how to avoid them?

Why do we use the plural of movies in this phrase "We went to the movies last night."?

How to solve a differential equation with a term to a power?

Is it professional to write unrelated content in an almost-empty email?

sp_blitzCache results Memory grants

Written every which way

What was the first Unix version to run on a microcomputer?

How to start emacs in "nothing" mode (`fundamental-mode`)

Why is the US ranked as #45 in Press Freedom ratings, despite its extremely permissive free speech laws?

Is there a difference between "Fahrstuhl" and "Aufzug"

Is it possible to search for a directory/file combination?

Between two walls

Return the Closest Prime Number

Should I tutor a student who I know has cheated on their homework?

How to invert MapIndexed on a ragged structure? How to construct a tree from rules?

Would this house-rule that treats advantage as a +1 to the roll instead (and disadvantage as -1) and allows them to stack be balanced?

Is micro rebar a better way to reinforce concrete than rebar?

Rotate a column

Different harmonic changes implied by a simple descending scale

Limits on contract work without pre-agreed price/contract (UK)

Sending manuscript to multiple publishers

Are there any unintended negative consequences to allowing PCs to gain multiple levels at once in a short milestone-XP game?

Can you replace a racial trait cantrip when leveling up?



I want to swap the position of two bits. How to do this?



The Next CEO of Stack OverflowWhat are the segment and offset in real mode memory addressing?How to right rotate a 64-bit value efficiently in ARM7 assembler?IA-32e 64-bit IDT Gate DescriptorBase pointer and stack pointerx86 - segmentation in protected mode serves what purpose?conceptual help understanding OFFSET Function and the ways in which this program outputsReplacing a 32-bit loop counter with 64-bit introduces crazy performance deviationsAccessing the Program Segment PrefixWhat happens to instruction pointers when address overrides are used to target a smaller address space?Verify that in a range of bits only one is on










1















I am given a question in which I have to write a program such that the last bit of the offset address of the first segment becomes the first bit of the offset address of the second segment. For example if I am given ABCDH then the offset address of the second address should be DCBAH. I am just focusing on the swapping of the offset address and am ignoring the base address for now:



MOV AX,ABCDH
ROR AX,16 ; this will rotate the value of AX 16 times


Now we have CDABH. Now I want to swap the position of D and C. I am stuck at this point. Will I use SAR command?










share|improve this question



















  • 5





    You have mixed 1, 2 and 4 bit units all over the place. If you really need to turn ABCDh into DCBAh that's reversing using 4 bit units. Obviously ror ax, 2 will rotate by 2 bits which will not give CDABh as you claim. To get CDABh you want to rotate by 2 bytes which is 16 bits.

    – Jester
    Mar 7 at 15:49






  • 2





    @Jester: 2 hex digits = 1 byte, so ror ax, 8. If C, D, A, B are placeholders for whole bytes, then yes ror eax, 16. This question is so mixed up between bits, nibbles, and bytes that it apparently got you mixed up :P

    – Peter Cordes
    Mar 7 at 23:07












  • Reversing the bits of 0ABCDH (not ABCDH, by the way) results in 0B3D5H, not 0DCBAH.

    – TonyK
    Mar 10 at 17:47















1















I am given a question in which I have to write a program such that the last bit of the offset address of the first segment becomes the first bit of the offset address of the second segment. For example if I am given ABCDH then the offset address of the second address should be DCBAH. I am just focusing on the swapping of the offset address and am ignoring the base address for now:



MOV AX,ABCDH
ROR AX,16 ; this will rotate the value of AX 16 times


Now we have CDABH. Now I want to swap the position of D and C. I am stuck at this point. Will I use SAR command?










share|improve this question



















  • 5





    You have mixed 1, 2 and 4 bit units all over the place. If you really need to turn ABCDh into DCBAh that's reversing using 4 bit units. Obviously ror ax, 2 will rotate by 2 bits which will not give CDABh as you claim. To get CDABh you want to rotate by 2 bytes which is 16 bits.

    – Jester
    Mar 7 at 15:49






  • 2





    @Jester: 2 hex digits = 1 byte, so ror ax, 8. If C, D, A, B are placeholders for whole bytes, then yes ror eax, 16. This question is so mixed up between bits, nibbles, and bytes that it apparently got you mixed up :P

    – Peter Cordes
    Mar 7 at 23:07












  • Reversing the bits of 0ABCDH (not ABCDH, by the way) results in 0B3D5H, not 0DCBAH.

    – TonyK
    Mar 10 at 17:47













1












1








1








I am given a question in which I have to write a program such that the last bit of the offset address of the first segment becomes the first bit of the offset address of the second segment. For example if I am given ABCDH then the offset address of the second address should be DCBAH. I am just focusing on the swapping of the offset address and am ignoring the base address for now:



MOV AX,ABCDH
ROR AX,16 ; this will rotate the value of AX 16 times


Now we have CDABH. Now I want to swap the position of D and C. I am stuck at this point. Will I use SAR command?










share|improve this question
















I am given a question in which I have to write a program such that the last bit of the offset address of the first segment becomes the first bit of the offset address of the second segment. For example if I am given ABCDH then the offset address of the second address should be DCBAH. I am just focusing on the swapping of the offset address and am ignoring the base address for now:



MOV AX,ABCDH
ROR AX,16 ; this will rotate the value of AX 16 times


Now we have CDABH. Now I want to swap the position of D and C. I am stuck at this point. Will I use SAR command?







assembly x86 x86-emulation






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 10 at 14:38







Ahmad Qayyum

















asked Mar 7 at 15:22









Ahmad QayyumAhmad Qayyum

335




335







  • 5





    You have mixed 1, 2 and 4 bit units all over the place. If you really need to turn ABCDh into DCBAh that's reversing using 4 bit units. Obviously ror ax, 2 will rotate by 2 bits which will not give CDABh as you claim. To get CDABh you want to rotate by 2 bytes which is 16 bits.

    – Jester
    Mar 7 at 15:49






  • 2





    @Jester: 2 hex digits = 1 byte, so ror ax, 8. If C, D, A, B are placeholders for whole bytes, then yes ror eax, 16. This question is so mixed up between bits, nibbles, and bytes that it apparently got you mixed up :P

    – Peter Cordes
    Mar 7 at 23:07












  • Reversing the bits of 0ABCDH (not ABCDH, by the way) results in 0B3D5H, not 0DCBAH.

    – TonyK
    Mar 10 at 17:47












  • 5





    You have mixed 1, 2 and 4 bit units all over the place. If you really need to turn ABCDh into DCBAh that's reversing using 4 bit units. Obviously ror ax, 2 will rotate by 2 bits which will not give CDABh as you claim. To get CDABh you want to rotate by 2 bytes which is 16 bits.

    – Jester
    Mar 7 at 15:49






  • 2





    @Jester: 2 hex digits = 1 byte, so ror ax, 8. If C, D, A, B are placeholders for whole bytes, then yes ror eax, 16. This question is so mixed up between bits, nibbles, and bytes that it apparently got you mixed up :P

    – Peter Cordes
    Mar 7 at 23:07












  • Reversing the bits of 0ABCDH (not ABCDH, by the way) results in 0B3D5H, not 0DCBAH.

    – TonyK
    Mar 10 at 17:47







5




5





You have mixed 1, 2 and 4 bit units all over the place. If you really need to turn ABCDh into DCBAh that's reversing using 4 bit units. Obviously ror ax, 2 will rotate by 2 bits which will not give CDABh as you claim. To get CDABh you want to rotate by 2 bytes which is 16 bits.

– Jester
Mar 7 at 15:49





You have mixed 1, 2 and 4 bit units all over the place. If you really need to turn ABCDh into DCBAh that's reversing using 4 bit units. Obviously ror ax, 2 will rotate by 2 bits which will not give CDABh as you claim. To get CDABh you want to rotate by 2 bytes which is 16 bits.

– Jester
Mar 7 at 15:49




2




2





@Jester: 2 hex digits = 1 byte, so ror ax, 8. If C, D, A, B are placeholders for whole bytes, then yes ror eax, 16. This question is so mixed up between bits, nibbles, and bytes that it apparently got you mixed up :P

– Peter Cordes
Mar 7 at 23:07






@Jester: 2 hex digits = 1 byte, so ror ax, 8. If C, D, A, B are placeholders for whole bytes, then yes ror eax, 16. This question is so mixed up between bits, nibbles, and bytes that it apparently got you mixed up :P

– Peter Cordes
Mar 7 at 23:07














Reversing the bits of 0ABCDH (not ABCDH, by the way) results in 0B3D5H, not 0DCBAH.

– TonyK
Mar 10 at 17:47





Reversing the bits of 0ABCDH (not ABCDH, by the way) results in 0B3D5H, not 0DCBAH.

– TonyK
Mar 10 at 17:47












1 Answer
1






active

oldest

votes


















3















MOV AX,ABCDH
ROR AX,16 ; this will rotate the value of AX 16 times


Now we have CDABH




The AX register holds 16 bits. When you rotate these 16 bits 16 times you get the same value that you started with!




For example if I am given ABCDH then the offset address of the second address should be DCBAH




So you want to go from ABCDh to DCBAh.



The AX register is subdivided in 2 halves. The low half is named AL and the high half is named AH. You can operate on these halves independently.



The instruction mov ax, 0ABCDh puts the value 0ABh in AH and puts the value 0CDh in AL.



mov ax, 0ABCDh ; AH = 0ABh AL = 0CDh
rol al, 4 ; AH = 0ABh AL = 0DCh
rol ah, 4 ; AH = 0BAh AL = 0DCh
xchg al, ah ; AH = 0DCh AL = 0BAh


Now finally AX=0DCBAh.




All of the above deals with 4-bit quantities. We call these nibbles.

You can write your hexadecimal value 0ABCDh using the binary representation like 1010101111001101b. You can see that there are 16 bits.



Aligned groups of bits have special names:



  • every 4 bits form a nibble, you can see that there are 4 nibbles. (1010 1011 1100 1101)

  • every 8 bits form a byte, you can see that there are 2 bytes. (10101011 11001101)

  • every 16 bits form a word, you can see that there is 1 word. (1010101111001101)





share|improve this answer

























    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55047264%2fi-want-to-swap-the-position-of-two-bits-how-to-do-this%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    3















    MOV AX,ABCDH
    ROR AX,16 ; this will rotate the value of AX 16 times


    Now we have CDABH




    The AX register holds 16 bits. When you rotate these 16 bits 16 times you get the same value that you started with!




    For example if I am given ABCDH then the offset address of the second address should be DCBAH




    So you want to go from ABCDh to DCBAh.



    The AX register is subdivided in 2 halves. The low half is named AL and the high half is named AH. You can operate on these halves independently.



    The instruction mov ax, 0ABCDh puts the value 0ABh in AH and puts the value 0CDh in AL.



    mov ax, 0ABCDh ; AH = 0ABh AL = 0CDh
    rol al, 4 ; AH = 0ABh AL = 0DCh
    rol ah, 4 ; AH = 0BAh AL = 0DCh
    xchg al, ah ; AH = 0DCh AL = 0BAh


    Now finally AX=0DCBAh.




    All of the above deals with 4-bit quantities. We call these nibbles.

    You can write your hexadecimal value 0ABCDh using the binary representation like 1010101111001101b. You can see that there are 16 bits.



    Aligned groups of bits have special names:



    • every 4 bits form a nibble, you can see that there are 4 nibbles. (1010 1011 1100 1101)

    • every 8 bits form a byte, you can see that there are 2 bytes. (10101011 11001101)

    • every 16 bits form a word, you can see that there is 1 word. (1010101111001101)





    share|improve this answer





























      3















      MOV AX,ABCDH
      ROR AX,16 ; this will rotate the value of AX 16 times


      Now we have CDABH




      The AX register holds 16 bits. When you rotate these 16 bits 16 times you get the same value that you started with!




      For example if I am given ABCDH then the offset address of the second address should be DCBAH




      So you want to go from ABCDh to DCBAh.



      The AX register is subdivided in 2 halves. The low half is named AL and the high half is named AH. You can operate on these halves independently.



      The instruction mov ax, 0ABCDh puts the value 0ABh in AH and puts the value 0CDh in AL.



      mov ax, 0ABCDh ; AH = 0ABh AL = 0CDh
      rol al, 4 ; AH = 0ABh AL = 0DCh
      rol ah, 4 ; AH = 0BAh AL = 0DCh
      xchg al, ah ; AH = 0DCh AL = 0BAh


      Now finally AX=0DCBAh.




      All of the above deals with 4-bit quantities. We call these nibbles.

      You can write your hexadecimal value 0ABCDh using the binary representation like 1010101111001101b. You can see that there are 16 bits.



      Aligned groups of bits have special names:



      • every 4 bits form a nibble, you can see that there are 4 nibbles. (1010 1011 1100 1101)

      • every 8 bits form a byte, you can see that there are 2 bytes. (10101011 11001101)

      • every 16 bits form a word, you can see that there is 1 word. (1010101111001101)





      share|improve this answer



























        3












        3








        3








        MOV AX,ABCDH
        ROR AX,16 ; this will rotate the value of AX 16 times


        Now we have CDABH




        The AX register holds 16 bits. When you rotate these 16 bits 16 times you get the same value that you started with!




        For example if I am given ABCDH then the offset address of the second address should be DCBAH




        So you want to go from ABCDh to DCBAh.



        The AX register is subdivided in 2 halves. The low half is named AL and the high half is named AH. You can operate on these halves independently.



        The instruction mov ax, 0ABCDh puts the value 0ABh in AH and puts the value 0CDh in AL.



        mov ax, 0ABCDh ; AH = 0ABh AL = 0CDh
        rol al, 4 ; AH = 0ABh AL = 0DCh
        rol ah, 4 ; AH = 0BAh AL = 0DCh
        xchg al, ah ; AH = 0DCh AL = 0BAh


        Now finally AX=0DCBAh.




        All of the above deals with 4-bit quantities. We call these nibbles.

        You can write your hexadecimal value 0ABCDh using the binary representation like 1010101111001101b. You can see that there are 16 bits.



        Aligned groups of bits have special names:



        • every 4 bits form a nibble, you can see that there are 4 nibbles. (1010 1011 1100 1101)

        • every 8 bits form a byte, you can see that there are 2 bytes. (10101011 11001101)

        • every 16 bits form a word, you can see that there is 1 word. (1010101111001101)





        share|improve this answer
















        MOV AX,ABCDH
        ROR AX,16 ; this will rotate the value of AX 16 times


        Now we have CDABH




        The AX register holds 16 bits. When you rotate these 16 bits 16 times you get the same value that you started with!




        For example if I am given ABCDH then the offset address of the second address should be DCBAH




        So you want to go from ABCDh to DCBAh.



        The AX register is subdivided in 2 halves. The low half is named AL and the high half is named AH. You can operate on these halves independently.



        The instruction mov ax, 0ABCDh puts the value 0ABh in AH and puts the value 0CDh in AL.



        mov ax, 0ABCDh ; AH = 0ABh AL = 0CDh
        rol al, 4 ; AH = 0ABh AL = 0DCh
        rol ah, 4 ; AH = 0BAh AL = 0DCh
        xchg al, ah ; AH = 0DCh AL = 0BAh


        Now finally AX=0DCBAh.




        All of the above deals with 4-bit quantities. We call these nibbles.

        You can write your hexadecimal value 0ABCDh using the binary representation like 1010101111001101b. You can see that there are 16 bits.



        Aligned groups of bits have special names:



        • every 4 bits form a nibble, you can see that there are 4 nibbles. (1010 1011 1100 1101)

        • every 8 bits form a byte, you can see that there are 2 bytes. (10101011 11001101)

        • every 16 bits form a word, you can see that there is 1 word. (1010101111001101)






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Mar 14 at 15:15









        Fifoernik

        7,79511324




        7,79511324










        answered Mar 10 at 20:50









        Sep RolandSep Roland

        12.4k22047




        12.4k22047





























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55047264%2fi-want-to-swap-the-position-of-two-bits-how-to-do-this%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            AWS Lex not identifying response if by a variable The 2019 Stack Overflow Developer Survey Results Are In Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) The Ask Question Wizard is Live! Data science time! April 2019 and salary with experienceEnforcing custom enumeration in AWS LEX for slot valuesHow to give response based on user response in Amazon Lex?Intercepting AWS Lambda Response to a AWS Lex QueryLex chat bot error: Reached second execution of fulfillment lambda on the same utteranceamazon lex showing invalid responseLambda response send back to Lex slot?Response card in Amazon lexAmazon Lex - Lambda response return HTML to botHow can I solve 424 (Failed Dependency) (python) obtained from Amazon lex?

            Алба-Юлія

            Захаров Федір Захарович