Hi!

I asked myself:

Why does this work:


push wParam ; wParam WPARAM <- is initialized
pop char ; char WPARAM ?

and this doesn't:
mov char,wParam


?
I don't understand
Posted on 2002-07-23 18:05:07 by Subby
you cant mov mem to mem

you need to use some other ways
like push pop
or moving the data to reg and from reg to mem
Posted on 2002-07-23 18:14:56 by eko
Yup, it's a limitation in the x86 architecture, there isn't a memory to memory addressing mode. You can use the MOVS string instructions, with or without REP, but you'ld need to setup ESI and EDI first.

:)
Posted on 2002-07-23 18:41:33 by S/390
Use the m2m macro, this will ease the pain from typing push and pop.
m2m MACRO M1:REQ, M2:REQ

push M2
pop M1
ENDM

Usage: m2m char, wParam
Posted on 2002-07-23 19:48:22 by stryker
hmmmm? stryker...That would save typing push and pop but you still have to call the macro for the values so your typing more aren't you . And i think there would be more instructions/cpu usage because internally there would be far or near addressing going on would'nt there.
Posted on 2002-07-23 21:25:15 by IwasTitan
It depends on your convenience. If you want to use it for a more nice looking code then use it, else don't.

As for typing more? I don't think so.

push wParam
pop char

vs.

m2m char, wParam

count the letters....

Remember invoke is a macro, addr is a macro ... These macros have more type checkings, data manipulation and has more macro code in it than m2m. ;)
Posted on 2002-07-23 21:30:24 by stryker
push/pop are very slow because each instruction is memory to memory (in worst case). Surely, this code would be faster:
mov	eax, src

mov dest, eax

But its of course larger in size than push/pop and takes up a register. For such small issue it really doesn't matter which you use though.
Posted on 2002-07-23 22:44:02 by comrade
I had to consult the opcode manual to convince myself but Comrade is correct. Using mov for subby's code would require the least amount of clock cycles. Pop and push require 4 times that amount so if your prog iterated subbys code many times there would be great savings of processor time using mov instead of pop/push.


And stryker is also correct from the readability point of view.

:alright:
Posted on 2002-07-24 12:13:06 by IwasTitan
actually that macro isn't mine, I got it from one of the examples in masm32. ::> Total Ripoff <:: (I never gave the credit to the author and made it look like I made it myself) :o :grin: personally, I don't use that macro. :alright:

Regards, Posted on 2002-07-24 12:21:53 by stryker
; memory to memory move through register

m3m MACRO mem1:REQ, reg:REQ, mem2:REQ
mov reg,mem2
mov mem1,reg
ENDM

; example
m3m Destination, esi, Source
This is a handy one to keep around the tool shed.
Posted on 2002-07-24 12:31:40 by bitRAKE
Grate MACRO, bitRAKE!

But, using a differnt kind of macro-instructions, those of FASM, this one comes very handy too:
macro mov arg1,arg2

{
if arg1 in <ds,es,fs,gs,ss> & arg2 in <cs,ds,es,fs,gs,ss>
push arg2
pop arg1
else
mov arg1,arg2 ; here original mov instruction will be used
end if
}
macro mov arg1,arg2,arg3
{
if <arg3> eq <>
mov arg1,arg2 ; here previous macro will be used
else
mov arg1,arg2
mov arg2,arg3
end if
}
mov ax,bx ; just 'mov ax,bx'
mov ds,es ; 'push es' and 'pop ds'
mov es,ds,dx ; 'push ds', 'pop es' and 'mov ds,dx'


Actually this example from Posted on 2002-07-24 13:00:38 by slop
I use m2m once in a while too, its great. I also took it off from one of the examples in masm32. :P
Posted on 2002-07-24 13:29:36 by comrade
Macros i use tryes to optimize code it generates a bit.
Common use:
_mov xxx, yyy

To generate yyy -> eax -> xxx use:
_mov xxx, yyy, eax


;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

$IsImm MACRO Operand:REQ
IF (OPATTR (Operand)) AND 00000100y
;; Is an immediate value
EXITM <-1>
ELSE
EXITM <0>
ENDIF
ENDM

;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

$IsReg MACRO Operand:REQ
IF (OPATTR (Operand)) AND 00010000y
;; Is a register value
EXITM <-1>
ELSE
EXITM <0>
ENDIF
ENDM

;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

m2m MACRO Des:REQ, Sor:REQ, Reg

IFB <Reg>
push Sor ;; Default size optimization
pop Des
ELSE
IF $IsReg(Reg)
mov Reg, Sor
mov Des, Reg
ELSE
.ERR <m2m macro ERROR! Specify register value as third param.>
ENDIF
ENDIF
ENDM

;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

_mov MACRO Des:REQ, Sor:REQ, Reg
; Four-F, 2001
local x, r

;; *** Source is a register ***
IF $IsReg(Sor)
IFDIFI <Des>, <Sor> ;; source and destination are different
mov Des, Sor
ENDIF
;; *** Source is constant ***
ELSEIF $IsImm(Sor)
IFE Sor ;; == 0
IF $IsReg(Des) ;; Destination is register
xor Des, Des
ELSE
and Des, 0
ENDIF
ELSEIF Sor EQ 1
IF $IsReg(Des) ;; Destination is register
xor Des, Des
inc Des
ELSE
mov Des, Sor
ENDIF
ELSEIF Sor EQ -1
IF $IsReg(Des) ;; Destination is register
or Des, -1
;; xor Des, Des / dec Des
ELSE
or Des, -1
ENDIF
ELSEIF (Sor GT -129) AND (Sor LT 128) ;; -129 < Sor < 128
IF $IsReg(Des) ;; Destination is register
mov Des, Sor
ELSE
mov Des, Sor
ENDIF
ELSE
mov Des, Sor
ENDIF
ELSE
;; *** Source is memory (NOT Reg AND NOT Imm) ***
IF $IsReg(Des) ;; Destination is a register
mov Des, Sor
ELSE
IFDIF <Des>, <Sor> ;; source and destination are different
m2m <Des>, <Sor>, <Reg>
ENDIF
ENDIF
ENDIF
ENDM

;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
Posted on 2002-07-24 16:18:46 by Four-F