|
|
Difference between SAR and IDIV???
Hello all,
can anyone explain the difference between SAR and IDIV. From my quick
reference booklet I see that both do signed divisions by 2 ... what confuses
me is the rounding operation. For SAR my booklet says that it does this
division with "rounding toward negative infinity" while for the IDIV
instruction it says that non integral quotients are truncated toward 0.
Thank you.
Bob Rock
|
|
0
|
|
|
|
Reply
|
Bob
|
9/2/2003 6:17:40 PM |
|
> can anyone explain the difference between SAR and IDIV. From my
> quick reference booklet I see that both do signed divisions by 2
> ... what confuses me is the rounding operation. For SAR my
> booklet says that it does this division with "rounding toward
> negative infinity" while for the IDIV instruction it says that
> non integral quotients are truncated toward 0.
How can you divide by 7 with SAR?
|
|
0
|
|
|
|
Reply
|
Nudge
|
9/2/2003 8:46:22 PM
|
|
> can anyone explain the difference between SAR and IDIV. From my quick
> reference booklet I see that both do signed divisions by 2 ... what
confuses
> me is the rounding operation. For SAR my booklet says that it does this
> division with "rounding toward negative infinity" while for the IDIV
> instruction it says that non integral quotients are truncated toward 0.
number to -inf. to 0
+4.6 +4 +4
+4.4 +4 +4
+0.1 0 0
-0.1 -1 0
-4.4 -5 -4
-4.6 -5 -4
|
|
0
|
|
|
|
Reply
|
Bx
|
9/2/2003 10:46:33 PM
|
|
On Tue, 2 Sep 2003 20:17:40 +0200
"Bob Rock" <nospam.yet_another_apprentice@hotmail.com> wrote:
:can anyone explain the difference between SAR and IDIV. From my quick
:reference booklet I see that both do signed divisions by 2
IDIV can also divide by a lot of other numbers, but I will assume that you
already know that. :-)
:... what confuses
:me is the rounding operation. For SAR my booklet says that it does this
:division with "rounding toward negative infinity" while for the IDIV
:instruction it says that non integral quotients are truncated toward 0.
The description makes the instructions sound more complicated than they
really are. To begin with, neither instruction does any actual rounding.
However, if the programmer ignores the remainder from the IDIV, or the
carry from the SAR, then the result can be said to be truncated or rounded.
If you don't like the default behavior, you can test the carry or the
remainder, and do your own rounding.
In addition, the distinction between "rounding toward negative infinity"
and "truncated toward 0" is only meaningful when dealing with negative odd
numbers, and stems from the fact that IDIV was designed to be aware how
negative numbers are represented, while SAR is just shifting an arbitrary
string of bits, and propagating the high order bit as it does so.
>From a practical point of view, using a shift instruction in place of a
divide instruction is a trick which can be used in certain situations when
speed is more important than
-- Chuck
|
|
0
|
|
|
|
Reply
|
Charles
|
9/2/2003 11:37:28 PM
|
|
|
3 Replies
466 Views
(page loaded in 0.041 seconds)
|
|
|
|
|
|
|
|
|