News:

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

Macro I need explication

Started by Fernand, September 14, 2007, 02:09:59 PM

Previous topic - Next topic

Fernand

I every body...I need your help  :bg
I do not undertannd thas macro....

      szText MACRO Name, Text:VARARG
        LOCAL lbl         ; This is a lebel
          jmp lbl           ; jmp lbl means jump to lbl:
            Name db Text,0           ; How the NameText can be = 0
          lbl:                ; This is the lebel
        ENDM

Fernand

jdoe

Fernand,

This macro let you declare a string in the .CODE instead of the .DATA section.
The string is not code so the jump make sure it is not executed.

The result looks like that ...


.CODE

invoke MyProc
invoke ExitProcess, 0

MyProc PROC

; szText szMyString,"This is my string"
jmp @F
szMyString BYTE "This is my string",0
@@:

mov eax, offset szMyString

ret

MyProc ENDP

END


Can be done this way either (without macro) ...


.CODE

invoke MyProc
invoke ExitProcess, 0

MyProc PROC

.DATA
szMyString BYTE "This is my string",0
.CODE

mov eax, offset szMyString

ret

MyProc ENDP

END



Vortex

Fernand,

The fn macro is another choice to insert NULL terminated strings to your code :


.386
.model flat,stdcall
option casemap : none

include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
include \masm32\include\user32.inc

include \masm32\macros\macros.asm

includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\user32.lib


.code

start:

    fn  MessageBox,0,"Hello from fn macro","Macro demo",MB_OK
    fn  ExitProcess,0

END start

Fernand

Thank for your reply
Excuse me if I had problem to expleme it. I am not a anglish men.

I try to learn how a macro works and I do not undertand ;
how this sentence can be read (Name db Text,0 ) in this macro if the line before, there is a jump...for my comprehention if there is a jmp to a lebel than the program jump to that lebel...
Fernand

jdoe

Quote from: Fernand on September 14, 2007, 10:40:33 PM
how this sentence can be read (Name db Text,0 ) in this macro if the line before, there is a jump...

"jmp" is an assembly mnemonic and not a macro directive. This jump is saying nothing to a MASM macro and this is why it is part of the output.
If you need a jump in a macro look for GOTO.

http://msdn2.microsoft.com/en-us/library/8t163bt0(VS.71).aspx

Also, you can look in the "help" folder of MASM32, you'll find informations about macros.


Fernand

Thank for your reply jdoe, you help me very much.

I know that: "jmp" is an assembly mnemonic and not a macro directive. 
But what I do not understand, is the way that the sentence is write...
If I am not correct will you please correct me ! :bg
The word "jmp lbl" means: jump to the lebel "lbl" How the program can read the next sentence (Name db Text,0) ?

       LOCAL lbl         ; This is a lebel
          jmp lbl           ; jmp lbl means jump to lbl:
            Name db Text,0           ; How the NameText can be = 0
          lbl:                ; This is the lebel
Fernand

jdoe


Fernand,

"Name db Text,0" must NOT be read by the program, it is there only to be part of the memory when the program is loaded and "Name" will point to that memory location. You'll be able to use it the same way as it was in the .DATA section.


szText szProgName, "Nom du programme"

invoke MessageBox, 0, addr szProgName, addr szProgName, 0

mov eax, offset szProgName
invoke MessageBox, 0, eax, eax, 0


I don't know how to explain this differently. Maybe someone else could do better than I.

Good luck


Fernand

Thank for your reply jdoe, you help me very much. :U

This time I indertang it. Your explication is very clear.
This is me... My anglish is not very good....

Fernand :cheekygreen: