Hello All,
If I'm reading things correctly, and not missing something simple,
both my tutorial and the pentium manuals indicate that DIV has one
operand only - the divisor.
But when I compile a simple C++ assignment using unsigned integers
(dword) division, both MS VS2005 C++ compiler and the Intel C++
compiler create assembly which uses a destination and a source operand
for the DIV instruction.
Here's the C++ code, followed by MASM from MS compiler and MASM from
Intel Compiler.
---------C++-------------------
int main(void)
{
unsigned int var1 = 4000U;
unsigned int var2 = 5000U;
unsigned int var3 = 6000U;
unsigned int var4 = 0U;
var4 = (var1 * var2) / (var1 * var3); //assembly below
cout << var4 << endl;
return 0;
}
---------------------------------
following are both assembly outputs for
"var4 = (var1 * var2) / (var1 * var3);"
------MASM MS COMPILER---------
mov eax,dword ptr [var1]
imul eax,dword ptr [var2]
mov ecx,dword ptr [var1]
imul ecx,dword ptr [var3]
xor edx,edx
div eax,ecx ;<====* taking dest & source here for div
mov dword ptr [var4],eax
--------------------------------------
-----MASM Intel Compiler------------
mov eax,dword ptr [var2]
imul eax,dword ptr [var1]
mov edx,dword ptr [var3]
imul edx,dword ptr [var1]
mov dword ptr [ebp-4],edx
xor edx,edx
mov ecx,dword ptr [ebp-4]
div eax,ecx
mov dword ptr [var4],eax
----------------------------------------
--
thanks,
Brian
To the best of my knowledge, I have:
1) asked a question specifically related to this newsgroup
2) not used my email to request answers be sent there
3) not top-posted
4) not used bad grammar that would make me appear more stupider
|
|
0
|
|
|
|
Reply
|
Brian
|
4/2/2007 2:05:51 PM |
|
On Apr 2, 7:05 am, Brian <spamt...@crayne.org> wrote:
>
> Here's the C++ code, followed by MASM from MS compiler and MASM from
> Intel Compiler.
First, you are confusing "MASM" with "Intel-like Assembly Syntax".
MASM is a specific language. Unless MASM has changed dramatically in
the most recent version, I can assure you that MASM will not assembled
the output below. Therefore, claiming it is "MASM" is technically
incorrect.
> div eax,ecx ;<====* taking dest & source here for div
Have you actually tried to *assemble* this code with any assembler?
As I said, MASM has never allowed this syntax in any version that I've
ever used. That's not to imply that some assemblers won't allow you to
specify the implied destination operand (HLA allows this, for
example). Just that I've not seen MASM allow this.
I would suggest that the output syntax these compilers produce is
really for "human eyes only" and not for use by a particular
assembler. I could be wrong, but that would be my first guess.
> --
> thanks,
> Brian
> To the best of my knowledge, I have:
> 1) asked a question specifically related to this newsgroup
> 2) not used my email to request answers be sent there
> 3) not top-posted
> 4) not used bad grammar that would make me appear more stupider
But you *have* posted extraneous information that wastes bandwidth :-)
And (4), of course, is incredibly poorly formulated, making it almost
self-contradictory :-)
Cheers,
Randy Hyde
|
|
0
|
|
|
|
Reply
|
rhyde
|
4/2/2007 8:02:28 PM
|
|
There IS only one operand specified!
There are three unsigned divide operations (DIV) and three signed
divide operations (IDIV).
A set of three are register al=ax/op ah=remainder
register ax=dx:ax/op dx=remainder
register eax=edx:eax/op edx=remainder
Only ONE operand is specified: the location of the divisor which can
be another register or a memory location (eacjh of the required width)
|
|
0
|
|
|
|
Reply
|
Terence
|
4/2/2007 11:10:59 PM
|
|
Brian wrote:
> Hello All,
>
> If I'm reading things correctly, and not missing something simple,
> both my tutorial and the pentium manuals indicate that DIV has one
> operand only - the divisor.
That's correct.
> But when I compile a simple C++ assignment using unsigned integers
> (dword) division, both MS VS2005 C++ compiler and the Intel C++
> compiler create assembly which uses a destination and a source operand
> for the DIV instruction.
....
> div eax,ecx ;<====* taking dest & source here for div
....
> div eax,ecx
That's interesting. Does it assemble? (not with Nasm!!!) If so, does it
assemble if you change it to "div ebx, ecx"? I'd say your compilers -
two different ones!!! - were misleading you. Can't say it's "wrong",
'cause it's a syntax issue - you could write an assembler that took
"framistan GP0;GP2<-GP0:GP2,GP1" and did the same thing. One of those
occasions we may need to speak machine language. F7 F1. What's your
compiler say?
Best,
Frank
|
|
0
|
|
|
|
Reply
|
Frank
|
4/3/2007 12:06:30 AM
|
|
I suspect Brian's compiler takes the
DIV eax,ecx
And disregards the first operand and produces code for
DIV ecx
since the dividend is always ax, ax:dx or eax:edx and the divisor is a
nother register (as ecx)
or a memory address.
It may be a symbolic notation, but certainly not the version of MASM
nor TASM that I use.
Even Intel's data on cpu instructions doesn't mention the AX part
Maybe a much later version of one of the assemblers?
|
|
0
|
|
|
|
Reply
|
Terence
|
4/3/2007 9:59:58 AM
|
|
|
4 Replies
218 Views
(page loaded in 0.356 seconds)
Similiar Articles: DIV: Number of Operands = 1? or 2? - comp.lang.asm.x86Hello All, If I'm reading things correctly, and not missing something simple, both my tutorial and the pentium manuals indicate that DIV has one operand only - the ... How to perform division ? - comp.lang.asm.x86... the first two above means a divide by either a memory or register operand. The x86 CPU knows for DIV or IDIV ... is done with: the number ... Division is one of the harder math ... whats the use of "data16 nop" instruction generated by gas on x86 ...... er/bttv.asm&q=3Ddata16%20lang:assembly The number ... read the gas manual it just states that "Operand ... rpms/binutils/devel binutils-2.17.50.0.2-amdfam10.patch, NONE, 1.1 ... cycle count for divide - comp.lang.asm.x86... is only for floats, meaning those > two operands got converted into float? ?? Integer division of ... It will depend on a number of factors. Assuming div reg32, m32 I think ... x86 instruction size length - comp.lang.asm.x86The second form allows an instruction to have 2 register operands or a register operand + memory operand. A large number of instructions encode like this including the ... How to perform integer div with SIMD? - comp.lang.asm.x86 ...DIV: Number of Operands = 1? or 2? - comp.lang.asm.x86 How to perform integer div with SIMD? - comp.lang.asm.x86 ..... to generate a set of starting values, then one or ... Unsigned Integer Overflow on Multiplication and Division - comp ...6.2.5p9 says: ... A computation involving unsigned operands can never ... modulo the number that is one ... occur during two's complement signed integer division ... Table for x86 arithmetic instructions - comp.lang.asm.x86 ...... for | information like the different possible operands ... m ;w/dw MUL can only use the latter two above. DIV and ... About floating number arithmetic - comp.lang.asm.x86 ... Division by Constant (again) - comp.lang.asm.x86Splitting number to four 3-byte part is a great idea. I actually found even ... a*2^48 + b*2^32 + c*2^16 + d ((a) + (b * 4) + (c * 2) + (d)) mod 7 1 division ! since 2^48 ... how to calcule the division modulo 2 reminder - comp.sys.hp48 ...Modulo operation - Wikipedia, the free encyclopedia In computing, the modulo operation finds the remainder of division of one number by another. Given two positive numbers ... DIV: Number of Operands = 1? or 2? - Application Forum at ...DIV: Number of Operands = 1? or 2? - ASM x86 ASM 370 . This is a discussion on DIV: Number of Operands = 1? or 2? - ASM x86 ASM 370; Hello All, If I'm reading things ... DIV: Number of Operands = 1? or 2? - comp.lang.asm.x86 | Computer ...Hello All, If I'm reading things correctly, and not missing something simple, both my tutorial and the pentium manuals indicate that DIV has one operand only - the ... 7/25/2012 4:23:28 PM
|