I just saw in the helppc file that a mov reg,mem and mov mem,reg take 1 clock clycle each on a 486. But a push (reg 32) and pop (reg 32) take 1 and 4 clock cycles respectively. Thena why should one use push and pop at all. i mean instead of - push eax pop eax we could use - mov temp,eax mov eax,temp which should be much faster. Then why use push,pop at all? I know a msg like this has been posted before but the reply was that spped is not criticla for loading api structures. But as far as i think we are using assembly only to gain that extra edge in speed so why not use all the optimization possible? PS - Sorry for th double post. Fisrt time it gave me a duplicate msg err so i thought the msg was not added. Any way to delete the previous post? This message was edited by MovingFulcrum, on 6/8/2001 11:11:13 PM
Posted on 2001-06-08 23:07:00 by MovingFulcrum
Hi well first of all dont belive everything they say about processors...now lets THINK a little.... how the hell is a micro going to write or read to memory in a single clock cycle? eh? 1.it has to FETCH the instructio first, 2.then to decode it 3.then to calculate the adress 4.then to output the adress on adress bus and wait for memory settle time 5.write data etc... got the picture? ONLY under some particular situations like a preloaded pipeline, cache hits 100% etc etc this will get 1 clock ...otherwise ;) (tip:they dont make commercials about this otherwise situation...but a cache miss can cost you 32 clock cycles ;( sometimes ) Now for PUSH/POP,... well the stack register uses simple calculations +/- (4) but the biggest advantage is the stack mechanism itself, like when you want to call recursive procedures...you can not know how many calls will be done and IF you use one static memory variable it will get overwriten ... besides the stack seelctor presumely points to a diffrent cache line and acces to the stack will (hopefully) mantain data and code cache line coherency, PROC's and HLL use the stack for parameter transfer. FORTH and other languages uses stack machines to operate (PostScript for example). Allmost any parser/evaluator will need stacks to do its job decently. but basicaly PUSH/POP is a fast saver for some local data you dont want to make a variable for ;)
Posted on 2001-06-08 23:31:00 by BogdanOntanu
MovingFulcrum, Basically they are different instructions, push + pop manipulate the stack where mov copied data from a register, memory or an immediate value into either a register or memory location. They do have some overlap but if for example you needed to push 6 values, mov will not do it properly, you would need a lot of extra stack variables to do it that way. For timings of instructions, use the help file from Agner Fog as it is much later than helppc and deals with instructions up to PIII level. Regards, hutch@pbq.com.au
Posted on 2001-06-08 23:41:00 by hutch--
;yo dude, that's avatar of yours is cool!!! what is he lis- ;tening to? "what is love, baby don't hurt me..." ? Thanks for the compliment abt the avatar,disease :grin: . He can listen to whatever u wnat him to :grin: ;For timings of instructions, use the help file from Agner Fog as ;it is much later than helppc and deals with instructions up to PIII level. Hutch can u tell me where to dl Agener Fog's helpfile from?
Posted on 2001-06-09 00:08:00 by MovingFulcrum
MovingFulcrum, Agner Fog's optimisation manual comes with MASM32, otherwise you can get it either from his home page or from mine, I produce the winhelp version for Agner Fog as it is a very important source of information for assembler language programmers. Regards, hutch@pbq.com.au
Posted on 2001-06-09 06:54:00 by hutch--
movingfulcrum... asm is not only about speed, but about size too... push reg and pop reg are 1 byte long, while each mov ,reg is at least 5 bytes. our code need be small to be able to be inserted in any place :cool: This message was edited by vecna, on 6/9/2001 1:46:31 PM
Posted on 2001-06-09 13:44:00 by vecna
Yes, an outstanding avatar, MF, and less than 20K, in the spirit of asm... You can sometimes save variables on the cpu instead of the stack or ds. xchg eax,reg32 is only one byte and quicker than using mem.
Posted on 2001-06-09 18:09:00 by Larry Hammick
Vecna, I don't suppose you could pull the plug on HYBRIS, the novelty stopped after the first 40 or so copies landed in my email. I found it the first time in a HEX editor so its not that smart. Regards, hutch@pbq.com.au
Posted on 2001-06-11 10:17:00 by hutch--