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
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
add a comment |
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
5
You have mixed 1, 2 and 4 bit units all over the place. If you really need to turnABCDhintoDCBAhthat's reversing using 4 bit units. Obviouslyror ax, 2will rotate by 2 bits which will not giveCDABhas you claim. To getCDABhyou want to rotate by 2 bytes which is 16 bits.
– Jester
Mar 7 at 15:49
2
@Jester: 2 hex digits = 1 byte, soror ax, 8. If C, D, A, B are placeholders for whole bytes, then yesror 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 of0ABCDH(notABCDH, by the way) results in0B3D5H, not0DCBAH.
– TonyK
Mar 10 at 17:47
add a comment |
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
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
assembly x86 x86-emulation
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 turnABCDhintoDCBAhthat's reversing using 4 bit units. Obviouslyror ax, 2will rotate by 2 bits which will not giveCDABhas you claim. To getCDABhyou want to rotate by 2 bytes which is 16 bits.
– Jester
Mar 7 at 15:49
2
@Jester: 2 hex digits = 1 byte, soror ax, 8. If C, D, A, B are placeholders for whole bytes, then yesror 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 of0ABCDH(notABCDH, by the way) results in0B3D5H, not0DCBAH.
– TonyK
Mar 10 at 17:47
add a comment |
5
You have mixed 1, 2 and 4 bit units all over the place. If you really need to turnABCDhintoDCBAhthat's reversing using 4 bit units. Obviouslyror ax, 2will rotate by 2 bits which will not giveCDABhas you claim. To getCDABhyou want to rotate by 2 bytes which is 16 bits.
– Jester
Mar 7 at 15:49
2
@Jester: 2 hex digits = 1 byte, soror ax, 8. If C, D, A, B are placeholders for whole bytes, then yesror 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 of0ABCDH(notABCDH, by the way) results in0B3D5H, not0DCBAH.
– 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
add a comment |
1 Answer
1
active
oldest
votes
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)
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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)
add a comment |
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)
add a comment |
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)
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)
edited Mar 14 at 15:15
Fifoernik
7,79511324
7,79511324
answered Mar 10 at 20:50
Sep RolandSep Roland
12.4k22047
12.4k22047
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
5
You have mixed 1, 2 and 4 bit units all over the place. If you really need to turn
ABCDhintoDCBAhthat's reversing using 4 bit units. Obviouslyror ax, 2will rotate by 2 bits which will not giveCDABhas you claim. To getCDABhyou 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 yesror 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(notABCDH, by the way) results in0B3D5H, not0DCBAH.– TonyK
Mar 10 at 17:47