News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

macro issue...

Started by PsYcHoCoDe, October 13, 2012, 08:40:18 PM

Previous topic - Next topic

PsYcHoCoDe

hey, guys, any idea how to define a label prefix+var inside a masm32 macro? i mean sth like prefix bla_VAR? ::)

jj2007

include \masm32\include\masm32rt.inc

MakeBla MACRO arg, value
   @CatStr(<bla>, <arg>, < dd >, %value)
ENDM

.data
   MakeBla Abc, 123
.code

start:   MsgBox 0, str$(blaAbc), "Hello World", MB_OK
   exit

end start

TouEnMasm


Just a help to write macro,allow to display partial result:
Quote
DISPLAY MACRO chaine           ;add a % to arg (%arg) if necessary
%ECHO chaine
ENDM
another syntax for CATSTR
Quote
    chain CATSTR <bla_>,<.>,<otherthing>,%indice


Fa is a musical note to play with CL

PsYcHoCoDe

it's gotta get like bla MACRO prefix_index and
jmp @another_prefix! :D

jj2007

Too much bla in your posts. Invest some time to explain what exactly you want to achieve, with a complete hello world example, and I may be willing to help you.

PsYcHoCoDe

#5
@TRY_BEGIN MACRO Handler
ASSUME FS:NOTHING
    pushad                          ; Save Current State
    ;mov esi, offset Handler         ; Address of New Exception Handler
    lea esi, [ebp+offset Handler]
    push esi                        ; Save Old Exception Handler
    push dword ptr fs:[0]           ; Install New Handler
    mov dword ptr fs:[0], esp
ENDM

@TRY_EXCEPT MACRO Handler
    jmp NoException_Handler        ; No Exception Occured, so jump over
Handler:
    mov esp, [esp + 8]              ; Exception Occured, Get old ESP
    pop dword ptr fs:[0]            ; Restore Old Exception Handler
    add esp, 4                      ; ESP value before SEH was set
    popad                           ; Restore Old State
ENDM

@TRY_END MACRO Handler
    jmp ExceptionHandled_Handler   ; Exception was handled by @TRY_EXCEPT
NoException_Handler:               ; No Exception Occured
    pop dword ptr fs:[0]            ; Restore Old Exception Handler
    add esp, 32 + 4                 ; ESP value before SEH was set. 32 for pushad and ...
ExceptionHandled_Handler:          ; ...4 for push offset Handler. (No Restore State)
ENDM                                ; Exception has been handled, or no exception occured


basically i just wanna make these nicely nestable... i.e. NoException_Handler: should be like NoException_PARAM. i hope i've explained it nicely  8)

PS: i just need to somehow make the labels uniquely generated... so i could nest the handlers... ;)

TouEnMasm


This one,working well,give an answer
Fa is a musical note to play with CL

qWord

Hello,
here an simple example for nesting:
@exh_nesting TEXTEQU <0>

@TRY_BEGIN MACRO
LOCAL lbl,lbl2
    @exh_nesting TEXTEQU %@exh_nesting + 1
%   @exh_lbl_&@exh_nesting& TEXTEQU <lbl>
%   @exh_ne_lbl_&@exh_nesting& TEXTEQU <lbl2>
   
    ASSUME FS:NOTHING
    pushad                          ; Save Current State
    push lbl                        ; pNext
    push dword ptr fs:[0]           ; Install New Handler
    mov dword ptr fs:[0], esp
ENDM

@TRY_EXCEPT MACRO
LOCAL lbl
%   jmp @exh_ne_lbl_&@exh_nesting&        ; No Exception Occured, so jump over
% @exh_lbl_&@exh_nesting&:
    ; unwinde code: ignore the failing code
    mov eax,[esp+12]
    mov [eax].CONTEXT.regEip,lbl
    xor eax,eax
    db 0c3h ; RET 0; to avoid problems with PROC's epilogue
lbl:
    pop dword ptr fs:[0]            ; Restore Old Exception Handler
    add esp,4
    popad                           ; Restore Old State
ENDM

@TRY_END MACRO Handler
LOCAL lbl
    jmp lbl   ; Exception was handled by @TRY_EXCEPT
% @exh_ne_lbl_&@exh_nesting&:       ; No Exception Occured
    pop dword ptr fs:[0]            ; Restore Old Exception Handler
    add esp, 32 + 4                 ; ESP value before SEH was set. 32 for pushad and ...
lbl:          ; ...4 for push offset Handler. (No Restore State)
    @exh_nesting TEXTEQU %@exh_nesting - 1
ENDM                                ; Exception has been handled, or no exception occured

test:
@TRY_BEGIN
    print "0",13,10
    @TRY_BEGIN
        print "n1",13,10
        xor ecx,ecx
        div ecx
    @TRY_EXCEPT
        print "nexp",13,10
    @TRY_END
    xor eax,eax
    mov eax,[eax]
@TRY_EXCEPT
    print "1",13,10
@TRY_END
MREAL macros - when you need floating point arithmetic while assembling!

PsYcHoCoDe

thank u, guys, that would really help!  :t it's perfect...  :eusa_dance: