News:

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

MACROS

Started by GUAN DE DIO, September 30, 2008, 09:12:18 AM

Previous topic - Next topic

GUAN DE DIO

Hi everybody,

   I wonder if there is a possibility to get a assemble code after 'compiled' the code. i.e.

   I'm using several macros like:
           
                     @ADD2
                      Mov rax,10
                      @SUB2

    And I want to get the assembled code result, something like this:

                    Add rax,2
                    Mov rax,10
                    Sub rax,2

     Is it possible? 
     How?

Thanks in advance,

GUAN

MazeGen

Not sure if I got your question. You mean something like this?


@ADD2 MACRO
add rax, 2
ENDM

@SUB2 MACRO
sub rax, 2
ENDM



.CODE
main PROC
@ADD2
mov rax, 10
@SUB2
main ENDP

END


Produces:


00000000 .CODE
00000000 main PROC
@ADD2
00000000  48/ 83 C0 02      1 add rax, 2
00000004  48/ C7 C0 mov rax, 10
   0000000A
@SUB2
0000000B  48/ 83 E8 02      1 sub rax, 2
0000000F main ENDP


This works for you? Or you need something more complicated?

BTW, you can ask these questions also on other subforums (The Campus) to get more answers because the ML64.EXE macro language is inherited from ML.EXE and works the same way.

GUAN DE DIO

Hi MazeGen,

     I explained me very bad :(

     The things is that I have a problem when I compiled my code, and it is very big now. I don't now where is the mistake but the fault is into a macro that is sure, so I ask for a way to get my code in asm with the generated code by the macro and in this way try to find the problem.

     Maybe I need to introduce a new flag in the ML64 or something.

GUAN 

MazeGen

So you need to debug your macros to see what wen wrong.

This code:


.LISTMACROALL

@ADD MACRO x:REQ
LOCAL y
y = x
add rax, y
ENDM
   
@SUB MACRO x:REQ
LOCAL y
y = x
sub rax, y
ENDM

.CODE
main PROC
@ADD 2
mov rax, 10
@SUB 2
main ENDP

END


Compiled with:

Quoteml64.exe /c /Fl test.asm

Creates this test.lst listing file:

Microsoft (R) Macro Assembler (x64) Version 8.00.50727.42   09/30/08 14:37:04
test.asm      Page 1 - 1


.LISTMACROALL

@ADD MACRO x:REQ
LOCAL y
y = x
add rax, y
ENDM
   
@SUB MACRO x:REQ
LOCAL y
y = x
sub rax, y
ENDM

00000000 .CODE
00000000 main PROC
@ADD 2
     1 LOCAL y
= 00000002      1 ??0000 = 2
00000000  48/ 83 C0 02      1 add rax, ??0000
00000004  48/ C7 C0 mov rax, 10
   0000000A
@SUB 2
     1 LOCAL y
= 00000002      1 ??0001 = 2
0000000B  48/ 83 E8 02      1 sub rax, ??0001
0000000F main ENDP

END
Microsoft (R) Macro Assembler (x64) Version 8.00.50727.42   09/30/08 14:37:04
test.asm      Symbols 2 - 1




Macros:

                N a m e                 Type

@ADD . . . . . . . . . . . . . . Proc
@SUB . . . . . . . . . . . . . . Proc


Procedures, parameters, and locals:

                N a m e                 Type     Value    Attr

main . . . . . . . . . . . . . . P 00000000 _TEXT Length= 0000000F Public


Symbols:

                N a m e                 Type     Value    Attr

??0000 . . . . . . . . . . . . . Number 00000002h   
??0001 . . . . . . . . . . . . . Number 00000002h   

   0 Warnings
   0 Errors


Now you can see how are your macros expanded.

The trick is /Fl command-line option which give you the .lst file.

Note the .LISTMACROALL directive at the top of the source. If you remove it, macro listing is reduced.

jj2007

You are aware of echo and .err? I use them a lot for debugging my macros.

include \masm32\include\masm32rt.inc

mbDebug MACRO slot:REQ, txt_title:REQ, args:VARARG
pushad
pushfd

echo
echo Hello! You gave me 'slot' and 'txt_title'
echo

hasq INSTR <txt_title>, <">
tmp$ CATSTR <The quote in the title is at position >, %hasq
% echo tmp$

.err ; ******* comment or delete '.err' to run the program *****************

ifndef mbDebugbuff
.data?
mbDebugbuff db 2048 dup (?)
.data
mbDebugbptr dd mbDebugbuff
mbDebugStop dd 5 dup (IDOK)
.code
endif
push offset mbDebugbuff
pop mbDebugbptr
mov byte ptr mbDebugbuff, 0
for arg, <args>
LOCAL tmp$, cc
cc INSTR <arg>, <$>
pushad
tmp$ CATSTR <chr$(">, <arg>, <")>
if cc
mov mbDebugbptr, cat$(mbDebugbptr, tmp$, chr$(9), <arg>, chr$(13, 10))
else
mov mbDebugbptr, cat$(mbDebugbptr, tmp$, chr$(9), sstr$(arg), chr$(13, 10))
endif
popad
ENDM
.if mbDebugStop+4*slot==IDOK
invoke MessageBox, 0, addr mbDebugbuff, reparg(txt_title), MB_OKCANCEL
.endif
mov mbDebugStop+4*slot, eax
popfd
popad
ENDM

.code

txMyPath db "MulDbgMacro.asm", 0
txMyGreets db 13,10,10, "Thanks to JimG for the fine tuning ;-)", 0
MyFilePath$ dd txMyPath
MyGreets$ dd txMyGreets

start:

    call main
    exit

main proc
    LOCAL MyCounter:DWORD, My2ndVar:DWORD, MyThirdVar:DWORD
    mov MyCounter, 111
    mov My2ndVar, 222
    mov MyThirdVar, 333
    .While MyCounter>0
pushad
mov eax, 1000001
mov ecx, 1000002
mov edx, 1000003
mov esi, 1000004
mov edi, 1000005
mov ebx, 1000006
mbDebug 0, "Show me the registers and five variables:", \
eax, ecx, edx, esi, edi, ebx, ebp, esp, \
MyCounter, MyThirdVar, MyFilePath$, MyGreets$
dec MyCounter
; mbDebug 1, "Show me the vars:", MyCounter, MyThirdVar, MyFilePath$
popad
    .Endw
    ret

main endp
end start

GUAN DE DIO

A lot of thanks,

   That's just I need it

GUAN