What is signed division(idiv) instruction?
In intel instruction, idiv(integer divsion) means signed division.
I got the result of idiv
, but I don't quite understand the result.
- Example
0xffff0000 idiv 0xffff1100
- My wrong prediction
As long as I know, quotient
should be 0, and remainder
should be 0xffff0000 and because...
0xffff0000 / 0xffff1100 = 0
0xffff0000 % 0xffff1100 = 0xffff0000
- However, the result was...
Before idiv
eax 0xffff0000 # dividend
esi 0xffff1100 # divisor
edx 0x0
After idiv
eax 0xfffeedcc # quotient
edx 0x7400 29696 # remainder
- Question.
The result was value I couldn't expected.
Could someone explain about signed division(idiv
)?
- Appended.
Here's More information about idiv
.idiv
uses the eax register as a source register.
As a result of execution, quotient is stored at eax, and remainder is stored at edx.
assembly x86 division integer-division signed-integer
add a comment |
In intel instruction, idiv(integer divsion) means signed division.
I got the result of idiv
, but I don't quite understand the result.
- Example
0xffff0000 idiv 0xffff1100
- My wrong prediction
As long as I know, quotient
should be 0, and remainder
should be 0xffff0000 and because...
0xffff0000 / 0xffff1100 = 0
0xffff0000 % 0xffff1100 = 0xffff0000
- However, the result was...
Before idiv
eax 0xffff0000 # dividend
esi 0xffff1100 # divisor
edx 0x0
After idiv
eax 0xfffeedcc # quotient
edx 0x7400 29696 # remainder
- Question.
The result was value I couldn't expected.
Could someone explain about signed division(idiv
)?
- Appended.
Here's More information about idiv
.idiv
uses the eax register as a source register.
As a result of execution, quotient is stored at eax, and remainder is stored at edx.
assembly x86 division integer-division signed-integer
You say "8086 instruction" but then you use "eax" and "edx" which are not 8086 registers. Please clarify. Note also that the idiv instruction uses the (e)dx register as a source register, which you did not specify.
– Raymond Chen
Jan 2 at 3:57
@RaymondChen Thank you for your advice. I edited my question to be more clear.
– Jiwon
Jan 2 at 4:05
@Jiwon - the question still doesn't show what is in edx before idiv.
– rcgldr
Jan 2 at 4:06
1
Have you looked at something like (idiv) IA-32 Assembly Language Reference Manual?
– David C. Rankin
Jan 2 at 4:18
Possible duplicate of IDIV in assembly isn't giving me the wanted result (NASM)
– Raymond Chen
Jan 2 at 15:34
add a comment |
In intel instruction, idiv(integer divsion) means signed division.
I got the result of idiv
, but I don't quite understand the result.
- Example
0xffff0000 idiv 0xffff1100
- My wrong prediction
As long as I know, quotient
should be 0, and remainder
should be 0xffff0000 and because...
0xffff0000 / 0xffff1100 = 0
0xffff0000 % 0xffff1100 = 0xffff0000
- However, the result was...
Before idiv
eax 0xffff0000 # dividend
esi 0xffff1100 # divisor
edx 0x0
After idiv
eax 0xfffeedcc # quotient
edx 0x7400 29696 # remainder
- Question.
The result was value I couldn't expected.
Could someone explain about signed division(idiv
)?
- Appended.
Here's More information about idiv
.idiv
uses the eax register as a source register.
As a result of execution, quotient is stored at eax, and remainder is stored at edx.
assembly x86 division integer-division signed-integer
In intel instruction, idiv(integer divsion) means signed division.
I got the result of idiv
, but I don't quite understand the result.
- Example
0xffff0000 idiv 0xffff1100
- My wrong prediction
As long as I know, quotient
should be 0, and remainder
should be 0xffff0000 and because...
0xffff0000 / 0xffff1100 = 0
0xffff0000 % 0xffff1100 = 0xffff0000
- However, the result was...
Before idiv
eax 0xffff0000 # dividend
esi 0xffff1100 # divisor
edx 0x0
After idiv
eax 0xfffeedcc # quotient
edx 0x7400 29696 # remainder
- Question.
The result was value I couldn't expected.
Could someone explain about signed division(idiv
)?
- Appended.
Here's More information about idiv
.idiv
uses the eax register as a source register.
As a result of execution, quotient is stored at eax, and remainder is stored at edx.
assembly x86 division integer-division signed-integer
assembly x86 division integer-division signed-integer
edited Jan 2 at 4:22
Peter Cordes
129k18194329
129k18194329
asked Jan 2 at 3:41
JiwonJiwon
329213
329213
You say "8086 instruction" but then you use "eax" and "edx" which are not 8086 registers. Please clarify. Note also that the idiv instruction uses the (e)dx register as a source register, which you did not specify.
– Raymond Chen
Jan 2 at 3:57
@RaymondChen Thank you for your advice. I edited my question to be more clear.
– Jiwon
Jan 2 at 4:05
@Jiwon - the question still doesn't show what is in edx before idiv.
– rcgldr
Jan 2 at 4:06
1
Have you looked at something like (idiv) IA-32 Assembly Language Reference Manual?
– David C. Rankin
Jan 2 at 4:18
Possible duplicate of IDIV in assembly isn't giving me the wanted result (NASM)
– Raymond Chen
Jan 2 at 15:34
add a comment |
You say "8086 instruction" but then you use "eax" and "edx" which are not 8086 registers. Please clarify. Note also that the idiv instruction uses the (e)dx register as a source register, which you did not specify.
– Raymond Chen
Jan 2 at 3:57
@RaymondChen Thank you for your advice. I edited my question to be more clear.
– Jiwon
Jan 2 at 4:05
@Jiwon - the question still doesn't show what is in edx before idiv.
– rcgldr
Jan 2 at 4:06
1
Have you looked at something like (idiv) IA-32 Assembly Language Reference Manual?
– David C. Rankin
Jan 2 at 4:18
Possible duplicate of IDIV in assembly isn't giving me the wanted result (NASM)
– Raymond Chen
Jan 2 at 15:34
You say "8086 instruction" but then you use "eax" and "edx" which are not 8086 registers. Please clarify. Note also that the idiv instruction uses the (e)dx register as a source register, which you did not specify.
– Raymond Chen
Jan 2 at 3:57
You say "8086 instruction" but then you use "eax" and "edx" which are not 8086 registers. Please clarify. Note also that the idiv instruction uses the (e)dx register as a source register, which you did not specify.
– Raymond Chen
Jan 2 at 3:57
@RaymondChen Thank you for your advice. I edited my question to be more clear.
– Jiwon
Jan 2 at 4:05
@RaymondChen Thank you for your advice. I edited my question to be more clear.
– Jiwon
Jan 2 at 4:05
@Jiwon - the question still doesn't show what is in edx before idiv.
– rcgldr
Jan 2 at 4:06
@Jiwon - the question still doesn't show what is in edx before idiv.
– rcgldr
Jan 2 at 4:06
1
1
Have you looked at something like (idiv) IA-32 Assembly Language Reference Manual?
– David C. Rankin
Jan 2 at 4:18
Have you looked at something like (idiv) IA-32 Assembly Language Reference Manual?
– David C. Rankin
Jan 2 at 4:18
Possible duplicate of IDIV in assembly isn't giving me the wanted result (NASM)
– Raymond Chen
Jan 2 at 15:34
Possible duplicate of IDIV in assembly isn't giving me the wanted result (NASM)
– Raymond Chen
Jan 2 at 15:34
add a comment |
1 Answer
1
active
oldest
votes
idiv
divides edx:eax by the explicit source operand. See Intel's instruction manual entry.
Since edx is 0, edx:eax is a positive number. You are dividing 4294901760 by -61184, giving -70196 with a remainder of 29696.
Remember that both dividend (EDX:EAX) and divisor (ESI in your case) are interpreted as 2's complement signed numbers, so any bit-pattern with the high bit set is negative.
00000000ffff0000 = 4294901760
ffff1100 = -61184
fffeedcc = -70196
7400 = 29696
You should sign extend eax into edx using cdq
before using idiv, instead of zero-extending by zeroing EDX.
However, that still won't give the results you were expecting, because -65536 divided by -61184 equals 1 with a remainder of -4352.
(A negative dividend and positive divisor would give a negative remainder: X86 IDIV sign of remainder depends on sign of dividend for 8/-3 and -8/3?)
1
Thank you for your detailed answer!
– Jiwon
Jan 2 at 8:12
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%2f54000965%2fwhat-is-signed-divisionidiv-instruction%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
idiv
divides edx:eax by the explicit source operand. See Intel's instruction manual entry.
Since edx is 0, edx:eax is a positive number. You are dividing 4294901760 by -61184, giving -70196 with a remainder of 29696.
Remember that both dividend (EDX:EAX) and divisor (ESI in your case) are interpreted as 2's complement signed numbers, so any bit-pattern with the high bit set is negative.
00000000ffff0000 = 4294901760
ffff1100 = -61184
fffeedcc = -70196
7400 = 29696
You should sign extend eax into edx using cdq
before using idiv, instead of zero-extending by zeroing EDX.
However, that still won't give the results you were expecting, because -65536 divided by -61184 equals 1 with a remainder of -4352.
(A negative dividend and positive divisor would give a negative remainder: X86 IDIV sign of remainder depends on sign of dividend for 8/-3 and -8/3?)
1
Thank you for your detailed answer!
– Jiwon
Jan 2 at 8:12
add a comment |
idiv
divides edx:eax by the explicit source operand. See Intel's instruction manual entry.
Since edx is 0, edx:eax is a positive number. You are dividing 4294901760 by -61184, giving -70196 with a remainder of 29696.
Remember that both dividend (EDX:EAX) and divisor (ESI in your case) are interpreted as 2's complement signed numbers, so any bit-pattern with the high bit set is negative.
00000000ffff0000 = 4294901760
ffff1100 = -61184
fffeedcc = -70196
7400 = 29696
You should sign extend eax into edx using cdq
before using idiv, instead of zero-extending by zeroing EDX.
However, that still won't give the results you were expecting, because -65536 divided by -61184 equals 1 with a remainder of -4352.
(A negative dividend and positive divisor would give a negative remainder: X86 IDIV sign of remainder depends on sign of dividend for 8/-3 and -8/3?)
1
Thank you for your detailed answer!
– Jiwon
Jan 2 at 8:12
add a comment |
idiv
divides edx:eax by the explicit source operand. See Intel's instruction manual entry.
Since edx is 0, edx:eax is a positive number. You are dividing 4294901760 by -61184, giving -70196 with a remainder of 29696.
Remember that both dividend (EDX:EAX) and divisor (ESI in your case) are interpreted as 2's complement signed numbers, so any bit-pattern with the high bit set is negative.
00000000ffff0000 = 4294901760
ffff1100 = -61184
fffeedcc = -70196
7400 = 29696
You should sign extend eax into edx using cdq
before using idiv, instead of zero-extending by zeroing EDX.
However, that still won't give the results you were expecting, because -65536 divided by -61184 equals 1 with a remainder of -4352.
(A negative dividend and positive divisor would give a negative remainder: X86 IDIV sign of remainder depends on sign of dividend for 8/-3 and -8/3?)
idiv
divides edx:eax by the explicit source operand. See Intel's instruction manual entry.
Since edx is 0, edx:eax is a positive number. You are dividing 4294901760 by -61184, giving -70196 with a remainder of 29696.
Remember that both dividend (EDX:EAX) and divisor (ESI in your case) are interpreted as 2's complement signed numbers, so any bit-pattern with the high bit set is negative.
00000000ffff0000 = 4294901760
ffff1100 = -61184
fffeedcc = -70196
7400 = 29696
You should sign extend eax into edx using cdq
before using idiv, instead of zero-extending by zeroing EDX.
However, that still won't give the results you were expecting, because -65536 divided by -61184 equals 1 with a remainder of -4352.
(A negative dividend and positive divisor would give a negative remainder: X86 IDIV sign of remainder depends on sign of dividend for 8/-3 and -8/3?)
edited Jan 2 at 4:41
Peter Cordes
129k18194329
129k18194329
answered Jan 2 at 4:10
prlprl
4,9631316
4,9631316
1
Thank you for your detailed answer!
– Jiwon
Jan 2 at 8:12
add a comment |
1
Thank you for your detailed answer!
– Jiwon
Jan 2 at 8:12
1
1
Thank you for your detailed answer!
– Jiwon
Jan 2 at 8:12
Thank you for your detailed answer!
– Jiwon
Jan 2 at 8:12
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%2f54000965%2fwhat-is-signed-divisionidiv-instruction%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
You say "8086 instruction" but then you use "eax" and "edx" which are not 8086 registers. Please clarify. Note also that the idiv instruction uses the (e)dx register as a source register, which you did not specify.
– Raymond Chen
Jan 2 at 3:57
@RaymondChen Thank you for your advice. I edited my question to be more clear.
– Jiwon
Jan 2 at 4:05
@Jiwon - the question still doesn't show what is in edx before idiv.
– rcgldr
Jan 2 at 4:06
1
Have you looked at something like (idiv) IA-32 Assembly Language Reference Manual?
– David C. Rankin
Jan 2 at 4:18
Possible duplicate of IDIV in assembly isn't giving me the wanted result (NASM)
– Raymond Chen
Jan 2 at 15:34