News:

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

Macro usage and tricks

Started by zemtex, April 06, 2012, 04:02:47 AM

Previous topic - Next topic

jj2007

Quote from: zemtex on April 15, 2012, 07:59:46 AM
Thanks, nice and simple. I can live with this.  :lol

ML.exe (and JWasm) has a really powerful macro engine, in contrast to other assemblers. Try this...

include \masm32\MasmBasic\MasmBasic.inc   ; download
   Init
   movlps xmm1, FP8(123.45678)
   mov eax, 100
   Inkey Str$("Xmm1*eax/ecx+PI=%f", f:xmm1*eax/1.2345678+PI)
   Exit
end start

Xmm1*eax/ecx+PI=10003.14

zemtex

I have a feeling you have been working hard on this masmbasic  :bg
I have been puzzling with lego bricks all my life. I know how to do this. When Peter, at age 6 is competing with me, I find it extremely neccessary to show him that I can puzzle bricks better than him, because he is so damn talented that all that is called rational has gone haywire.

jj2007

Quote from: zemtex on April 15, 2012, 08:15:19 AM
Example:    RVZ FunctionName Parameter1 Parameter2 n0

To have some flexibility, I would use a design that allows for variable arguments:
include \masm32\include\masm32rt.inc
rvz MACRO jmparg, API:REQ, args:VARARG
 is INSTR <jmparg>, <z:>
 invoke API, args
 test eax, eax
 if is eq 2
jne @SubStr(<jmparg>, is+2)
 else
je @SubStr(<jmparg>, is+2)
 endif
 EXITM <eax>
ENDM

.code
start:
print str$(rvz(z:Complain, GetSystemMetrics, 123 or SM_CMOUSEBUTTONS)), 13, 10
@@: inkey "bye"
exit

Complain:
print "There was an error!", 13, 10
jmp @B

end start

daydreamer

here is my unfinished work on fluxusmacros that is limited to handle cubes(8 coordinates)
I was aiming at inlining that 3d tree fluxus example I found on the web
PUSHSTATE MACRO
    FXSAVE [ebx]
    add ebx,512
    ENDM
    POPSTATE MACRO
    sub ebx,512
    FXRSTOR [ebx]
   
    ENDM
   
    TRANSLATE MACRO vectconst
    addps XMM0,vectconst
    addps XMM1,vectconst
    addps XMM2,vectconst
    addps XMM3,vectconst
    addps XMM4,vectconst
    addps XMM5,vectconst
    addps XMM6,vectconst
    addps XMM7,vectconst

    ENDM
    SCALE MACRO vectconst
    mulps XMM0,vectconst
    mulps XMM1,vectconst
    mulps XMM2,vectconst
    mulps XMM3,vectconst
    mulps XMM4,vectconst
    mulps XMM5,vectconst
    mulps XMM6,vectconst
    mulps XMM7,vectconst
    ENDM
   
    ;usage for example ROTATE vectconst1,X,Y,Z
    ;where first two is rotation axisconstants, last it the third axis not used
    ROTATE MACRO vectconst,coord1,coord2,coord3 ;not finished
    fld1
    fst tmpf1
    fst tmpf1+4
    fst tmpf1+8
    fst tmpf1+12
    fst tmpf2
    fst fmpf2+4
    fst tmpf2+8
    fstp tmpf2+12 ;mul coordinates not affected with 1.0
    fld vectconst
    fsincos
    fst tmpf1+coord1
    fstp tmpf1+coord2
    fst tmpf2+coord1
    fxch
    fstp tmpf2+coord2 ;generate cos,-sin and cos,sin
    fldz
    movaps xmm0tmp,XMM0 ;copy XMM0
    mulps XMM0,tmpf1 ;one mul XY
    movaps tmpf3,XMM0
    fstp tmpf3+coord3
    ;add zero to coordinates not effected
    mov eax,tmpf3+coord1
    xchg eax,tmpf3+coord2
    mov tmpf3+coord1,eax
    movaps tmpf2,XMM0
    mulps XMM0,xmm0tmp ;second mul XY
    addps XMM0,tmpf3 ;add xcos,-ysin with xsin,ycos
       
    ENDM
       

zemtex

New one:

How to define data in code section using macros, so that they are auto moved to data section or data? section.
Something like this:
DefineData MACRO Name:REQ, SomeText:REQ
       db Name "SomeText"
ENDM

Also..

When I have data defined in the data section, like this

SomeData db "Some text here"

and I have a textequ at the top like this:

Digit TEXTEQU %(32*2+1)

How can I add Digit in between Some and text as "65" and not as ascii character 'A'
I have been puzzling with lego bricks all my life. I know how to do this. When Peter, at age 6 is competing with me, I find it extremely neccessary to show him that I can puzzle bricks better than him, because he is so damn talented that all that is called rational has gone haywire.

qWord

DefineData macro lbl:req,txt:VARARG
    .data
        lbl db txt
    .code
endm


DefineData xyz,"Some ",65," text here",0
DefineData xyz,"Some ",Digit," text here",0
FPU in a trice: SmplMath
It's that simple!

jj2007

Quote from: zemtex on April 15, 2012, 04:10:03 PM
How to define data in code section using macros, so that they are auto moved to data section or data? section.

That's exactly what print "hello world", 13, 10 or print chr$("Hello World", 13, 10) do - see macros.asm...