News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Store (Push Pop)

Started by ragdog, March 18, 2011, 10:45:59 PM

Previous topic - Next topic

ragdog

Hi

What if the difference about store a variable (or waht if better)?

mov     eax, [esi].String
mov     [esi].String2, eax

or

push [edi].String
pop [edi].String2

I know both ways have the same effect

dedndave

the first example uses a register (EAX) - the second does not
sometimes - it is nice to save the register for something else
other times - you may want the value in register to do something else

sometimes, PUSH/POP is used to save a couple bytes of code when loading small constants...

mov eax,5  ;5 bytes

push 5      ;2 bytes
pop eax    ;1 byte

Hutch will argue one is faster - lol
and that size does not matter - all the gals i know say that size does matter
as for faster - i think there are cases where smaller is better - like in large loops

ragdog

Thanks

Lol 2 bytes differrent ::)


By 3 save variable function in my code make this 6 bytes and this by asm hmm not really important
by a routine what have a one call to save this variables.

I have read this http://www.masm32.com/board/index.php?topic=4024.0

Please move it!

Sorry

donkey

Quote from: ragdog on March 18, 2011, 11:49:33 PM
Thanks

Lol 2 bytes differrent ::)

Two bytes can be huge when you're struggling to limit a piece of code to a single cache line, with only 64 bytes to work with and the advantages gained it can, in some very specific cases, be more than worth the effort to squeeze every last byte out of a loop.
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable

jj2007

To put things into perspective:
On my Celeron M, the push/pop pair is 0.4 cycles slower than the mov equivalent. That is negligible in most circumstances except in an innermost loop that runs at least one-hundred Million times.

QuoteCPU: 1600000000 cycles/second
0.4/1600000000*100000000=25 ms

So if you have an application that relies on, say, delivering frames at a rate that needs to cheat the human eye, i.e. has to stay in the milliseconds range, and has a loop that runs one-hundred Million times, yes then the mov variant is better.

Anybody is able to show us such an application?
:bg

donkey

Quote from: jj2007 on March 19, 2011, 04:55:40 AM
Anybody is able to show us such an application?
:bg

Brute force encryption crackers are a violation of the rules of the forum.
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable

hutch--

Its pretty much the case that if you are writing API code the difference does not matter but in a speed critical algo where you have the register you are usually faster transferring the data through a register than on the stack. Instruction scheduling is the action, byte count is trivial.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

jj2007


hutch--

 :bg

Everyone has a theory, mine is convenience, thats why I use PUSH POP for non-critical code and MOV REG for critical code.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

donkey

#9
Quote from: jj2007 on March 19, 2011, 09:00:41 AM
Read reply #4 :bg

If you read it you would have noticed the "in some very specific cases" part.  ::)
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable

hutch--

 :bg

Everyone has a theory on "special cases". In the special case of non critical API code, PUSH POP works fine. In the special case of avoiding slow code in a speed critical algo transferring data through a register works fine. I can happily live with both without an arbitrary rule being applied. It is most probably the case that API code that copies data through a register will not explode your hard disk and if you want to write slow crappy code in a critical algo, no-one will lose any sleep over it.  :P
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

vanjast

Err Donkey, JJ in no way ventures close to any cracking, hacking etc... His was more specific to the video graphics side.
:lol