Question about assembly instruction on 386

Question about assembly instruction on 386

Post by Dongxiao Y » Wed, 14 Dec 1994 16:05:53



Hello, world.

I have a simple question about the PUSH instruction on 386.
It is used to put values on the stack especially for passing
parameters in func call or saving registers. However, the
same effect can be achieved using the MOV instruction.
My question is: which instruction is faster.
It seems to me that PUSH has to push the value and decrement the stack
pointer, my guess it is slower(or at most as fast as MOV).
If my guess is true, I will try to modify the compiler to use the MOV.

I should have posted this to some assembly group, but I think someone
reading these groups I  am posting to can help me.

Thanks,
Dongxiao

 
 
 

Question about assembly instruction on 386

Post by Hans Steffa » Wed, 14 Dec 1994 18:05:47



>Hello, world.
>I have a simple question about the PUSH instruction on 386.
>It is used to put values on the stack especially for passing
>parameters in func call or saving registers. However, the
>same effect can be achieved using the MOV instruction.
>My question is: which instruction is faster.
>It seems to me that PUSH has to push the value and decrement the stack
>pointer, my guess it is slower(or at most as fast as MOV).
>If my guess is true, I will try to modify the compiler to use the MOV.
>I should have posted this to some assembly group, but I think someone
>reading these groups I  am posting to can help me.

First this group is absolutl wrong for this kind of questions.
However you have to keep in mind that push/pop handles the stack-
pointer. I am not sure that there is a instruction to increment/decrement
the stack-pointer. But this is necessary for stacks! If there is
such a instruction, I am not sure if the needed two instructions, the mov
and the stack-ptr-instruction together as fast as PUSH/POP.
Assuming that PUSH/POP, MOV and this anknown stack-ptr-instruction are
as fast as possible your solution will be more slowly as one more
decode-cycle is necessary.

To solve you problem have a better look at the Intel-docs and do not
forget to proof your substitution for really being faster than the
original way.

And please do not send such questions to comp.lang.c because they are
OFF-TOPIC

H.F. Steffani

Quote:>Thanks,
>Dongxiao

--
Hans Friedrich Steffani
Institut fuer Elektrische Maschinen und Antriebe
TU Chemnitz-Zwickau


 
 
 

Question about assembly instruction on 386

Post by Dan P » Thu, 15 Dec 1994 04:32:03



Quote:>I have a simple question about the PUSH instruction on 386.
>It is used to put values on the stack especially for passing
>parameters in func call or saving registers. However, the
>same effect can be achieved using the MOV instruction.
>My question is: which instruction is faster.
>It seems to me that PUSH has to push the value and decrement the stack
>pointer, my guess it is slower(or at most as fast as MOV).
>If my guess is true, I will try to modify the compiler to use the MOV.

>I should have posted this to some assembly group, but I think someone

 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Quote:>reading these groups I  am posting to can help me.

 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

A true believer in Emily Postnews' advices :-)

I'm pretty sure someone reading alt.sex could help you.  Have you tried
there?

Dan
--
Dan Pop                       | The only reason God was able to make the
CERN, CN Division             | world in 7 days was he didn't have to remain

Mail:  CERN - PPE, Bat. 31 R-004, CH-1211 Geneve 23, Switzerland

 
 
 

Question about assembly instruction on 386

Post by Matt Be » Thu, 15 Dec 1994 07:11:38


[ Distribution of message limited to col.misc ]

: I have a simple question about the PUSH instruction on 386.
: It is used to put values on the stack especially for passing
: parameters in func call or saving registers. However, the
: same effect can be achieved using the MOV instruction.
: My question is: which instruction is faster.
: It seems to me that PUSH has to push the value and decrement the stack
: pointer, my guess it is slower(or at most as fast as MOV).
: If my guess is true, I will try to modify the compiler to use the MOV.

I assume you're referring to using:
         mov ax, [sp]   ; bad format - meant to put ax at location pointed
                        ; to by SP - my 386 assembly coding is fading :^)
as opposed to:
         push ax

On a 386, the former takes 4 clocks while the latter takes 2. Don't forget
for proper simulation of a push you should be adjusting SP, which is another
2 clocks. Either way you're still in a worse case than push. There's really
no reason to do a push manually if you don't have to.

Not to flame, but it's likely that if it were possible to make compiled
programs run better with such a trivial change then the compiler would
probably already do it :)

Matt

 
 
 

Question about assembly instruction on 386

Post by Dave Hayd » Thu, 15 Dec 1994 03:42:57



>Hello, world.
>I have a simple question about the PUSH instruction on 386.
>It is used to put values on the stack especially for passing
>parameters in func call or saving registers. However, the
>same effect can be achieved using the MOV instruction.
>My question is: which instruction is faster.
>It seems to me that PUSH has to push the value and decrement the stack
>pointer, my guess it is slower(or at most as fast as MOV).
>If my guess is true, I will try to modify the compiler to use the MOV.
>I should have posted this to some assembly group, but I think someone
>reading these groups I  am posting to can help me.

comp.lang.c isn't a good place for this question.  Nonetheless, you
are right that a PUSH is just a fancy MOVE.  You MUST decrement the
stack pointer however, because an interrupt can trash anything below
the stack pointer.  You should never store anything to the "wrong"
side of the stack.  It will eventually get clobbered by an interrupt.
Quote:>Thanks,
>Dongxiao

 
 
 

Question about assembly instruction on 386

Post by Timur Fanshte » Thu, 15 Dec 1994 14:10:38


: Hello, world.

: I have a simple question about the PUSH instruction on 386.
: It is used to put values on the stack especially for passing
: parameters in func call or saving registers. However, the
: same effect can be achieved using the MOV instruction.
: My question is: which instruction is faster.
: It seems to me that PUSH has to push the value and decrement the stack
: pointer, my guess it is slower(or at most as fast as MOV).
: If my guess is true, I will try to modify the compiler to use the MOV.

: I should have posted this to some assembly group, but I think someone
: reading these groups I  am posting to can help me.

: Thanks,
: Dongxiao
MOV is A LOT faster the push, As I beleave (Not sure thought) push is 14
cycles and MOV is I think 3 and Inc is 2 So even MOV + INC is faster then
PUSH, In case you are wondering PUSHA is I think 24 or something like that.

 
 
 

Question about assembly instruction on 386

Post by Dongxiao Y » Sat, 17 Dec 1994 03:06:32




>>I should have posted this to some assembly group, but I think someone
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>>reading these groups I  am posting to can help me.
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>A true believer in Emily Postnews' advices :-)
>I'm pretty sure someone reading alt.sex could help you.  Have you tried
>there?

  The second time somebody makes this suggestion, maybe not such a bad idea.
  However, to please everyone here, I decided to change(if not too late)
  the title of my orginal post to:

  "Possiblity for the C compiler to optimize C function calls"
  Subject: Can we make a C fucntion call  faster on  
           a CISC architecture using load/save operations?

 
 
 

Question about assembly instruction on 386

Post by Dongxiao Y » Sat, 17 Dec 1994 14:57:45




>>Hello, world.
>>I have a simple question about the PUSH instruction on 386.

[...]

Quote:>>I should have posted this to some assembly group, but I think someone
>>reading these groups I  am posting to can help me.
>First this group is absolutl wrong for this kind of questions.
>However you have to keep in mind that push/pop handles the stack-
>pointer. I am not sure that there is a instruction to increment/decrement
>the stack-pointer. But this is necessary for stacks! If there is

  If you consider it is so important, why do you think there is no
  instructions to modify the stack pointer. Do you think there
  is a magic switch that put everything in order when the machine boots,
  and then you can write C programs?

Quote:>such a instruction, I am not sure if the needed two instructions, the mov
>and the stack-ptr-instruction together as fast as PUSH/POP.
>Assuming that PUSH/POP, MOV and this anknown stack-ptr-instruction are
>as fast as possible your solution will be more slowly as one more
>decode-cycle is necessary.

  This is just your pure imagination.
  I received a lot of detailed and technical responses from this group,
  which showed the question is indeed not so simple and deserves some
  serious consideration.  

Quote:>And please do not send such questions to comp.lang.c because they are
>OFF-TOPIC

  First, I think the question I am asking is relavent to C programming.
  At an advanced level, a C programmer will inevitably encounter machine
  instructions, if you write a operating system, a compiler or a device
  driver, you do need to know some lower level stuff. I am not an assembly
  programmer, what I need to know is how to setup paging(and things like that),
  using a few assembly codes in my C program, then the magic can begin.
  Isn't asm a keyword of C and C++, why can't we discuss it for a brief moment?
  If all we talk about is
  stdio.h, life will be too boring. And I do believe that the power of C
  originates from its ability to directly address the lower level stuff.
  I thought I could have interesting  discussion with more intelligent
  and knowlegeble people in comp.lang.c. I have no intention to start
  a flame war here.

  Thanks for all the help,
  Dongxiao

 
 
 

Question about assembly instruction on 386

Post by Dan P » Sun, 18 Dec 1994 01:10:17





>>>I should have posted this to some assembly group, but I think someone
>> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>>>reading these groups I  am posting to can help me.
>> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

>>A true believer in Emily Postnews' advices :-)

>>I'm pretty sure someone reading alt.sex could help you.  Have you tried
>>there?

>  The second time somebody makes this suggestion, maybe not such a bad idea.
>  However, to please everyone here, I decided to change(if not too late)
>  the title of my orginal post to:

>  "Possiblity for the C compiler to optimize C function calls"
>  Subject: Can we make a C fucntion call  faster on  
>           a CISC architecture using load/save operations?

What is C specific in your reformulated question?  You can replace "C"
with "Fortran" or "Pascal" or many other languages.  

So, please go to alt.sex :-)

Dan
--
Dan Pop                       | The only reason God was able to make the
CERN, CN Division             | world in 7 days was he didn't have to remain

Mail:  CERN - PPE, Bat. 31 R-004, CH-1211 Geneve 23, Switzerland

 
 
 

Question about assembly instruction on 386

Post by Dave Schauma » Sun, 18 Dec 1994 13:34:44



>>>Hello, world.

>>>I have a simple question about the PUSH instruction on 386.
>>And please do not send such questions to comp.lang.c because they are
>>OFF-TOPIC

>  First, I think the question I am asking is relavent to C programming.

No.  It.  Is.  Not.

Sorry, thank you for being our contestant.

-Dave
--
***   ***   ***   ***   ***   ***   ***   ***   ***   ***   ***   ***   ***
  *     *     *     *     *     *     *     *     *     *     *     *     *
 *     *     *     *     *     *     *     *     *     *     *     *     *

 
 
 

1. compiling error: filds 386 asm instruction

Recently, many programs (i.e. WindowMaker 0.61.1 and
audiofile 0.1.9) are spitting out errors saying
"Assembler messages: Error: no such 386 instruction:
`filds' "

I am not sure what exactly the filds instruction
does.  All I've been able to confirm on my own is
that filds is indeed an x86 assembler instruction.

I have tried compiling under 2.2.x and 2.3.x kernels
with GCC 2.95.1 and GLIBC 2.1.2 for all instances.
LIBC5 is not installed nor is support for a.out
binaries (the system is 100% ELF).  Any help or
insight would be greatly appreciated.  Further
versions of programs and configurations can be
provided if necessary.

Thanks again.

Sent via Deja.com http://www.deja.com/
Before you buy.

2. 386/486 weirdness

3. 2.0.36 compile: no such 386 instruction: `rdtsc'

4. PPP update?

5. What 386 instruction is SALL meant to be!?

6. select() on RedHat 7.2

7. LCALL instruction in SVR3/386

8. C Library Reference

9. Kernel Compile error "No such 386 instruction"

10. Problems booting SV/386 on Intel AT-386-Computer

11. 386/ix mailx as distributed with 386/ix

12. Emulating 386 on 386 (was: Topic for discussion - future of WINE)

13. Sun Sparc - Assembly Instruction set