Hello i have a question ! ha, what is the diffrence between these two sets of code, my proffessor says there diffrent, i just cant figure out why, they both seem to do the same thing, this is my first time working with the coproccessor and im alittle stuck, thanks !

       fild      num1
       fild      num2
       fmul

       (vs)

       fild        num1

       fimul     num2

Not very sure, but here's my view :
1st case :
stack contains num1 at st(1) and num2 at st(0). So fmul causes num1*num2 result to be stored in st(0)

2nd Case:
stack only contains num1 at st(0), but num2 is not placed on stack. Result is stored at st(0)

The computed outcome is the same. The difference is in the stack contents after the operation is complete. In the first case, each FILD instruction pushes a value on the stack and the FMUL, having no arguments, multiplies the two values at the top of the stack, pops the top of stack and replaces the new top of stack with the result. That is, 2 pushes and one pop with the last 2 items on the stack having been discarded and the new end of stack being undefined (probably 0).

In the second case, the FILD instruction pushes a new value on the stack, discarding the end of stack value. Then the FIMUL computes the same result (num1 X num2) and replaces the top of stack with it.

In either case, ST contains the same result. The difference is that in the first case 2 items were lost from the end of the stack and one was replaced with an undefined value. In the second case, the last stack item was lost. If you needed one or the other of these values then you may have just written a bug into your code. The upshot is that both cases could be either OK or a disaster depending upon what else is on the stack at the time. Your Professor was correct in saying that the two cases are different. He just failed to say why.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.