flat assembler
Message board for the users of flat assembler.
Index
> Macroinstructions > Function definition [SOLVED] |
Author |
|
Kazyaka 27 Jan 2013, 23:13
@Edit:
After a short discussion I put here three ways to write macro which can define a funcion. If you don't know what I mean then feel free to read below posts. First Second Thrid Last edited by Kazyaka on 29 Jan 2013, 21:58; edited 2 times in total |
|||
27 Jan 2013, 23:13 |
|
Kazyaka 28 Jan 2013, 10:43
baldr wrote: Kazyaka, Nice idea, but it does too many useless operations for my needs. After a long time I made something like in FASM Documentation. Here's my macro: Code: macro Func name* { macro name { name: } EndFunc fix } Code: Func MyFunc inc ebx invoke MessageBox,HWND_DESKTOP,"My Func!",invoke GetCommandLine,MB_OK ret EndFunc |
|||
28 Jan 2013, 10:43 |
|
baldr 28 Jan 2013, 13:11
Kazyaka,
Your original post was too vague, now I understand: you want to make something like inline functionality. Then PutFunc name { name } (as you've used it in example) will expand macro created with Func/EndFunc at the place of invocation (simple MyFunc wil do that too: it's macroinstuction by definition). There is a problem though — ret inside Func/EndFunc definition probably will break program's execution path at the place of invocation. As a side note, why do you need something like MASM syntax MACRO/ENDM? Can you explain your idea? |
|||
28 Jan 2013, 13:11 |
|
Kazyaka 28 Jan 2013, 14:01
I often create large projects with many files. It'll simpler to me when I've macro like a Func/EndFunc.
As for program's break - I tested and it worked correctly for me. Take a look: main.asm Code: macro Func name*,[params] { macro name { name: } EndFunc fix } include 'win32ax.inc' include 'OneOfMyProjectFiles.inc' .code start: invoke MessageBox,HWND_DESKTOP,"Hi! I'm the examplae program!",invoke GetCommandLine,MB_OK stdcall MyFunc invoke ExitProcess,0 MyFunc .end start Code: Func MyFunc invoke MessageBox,HWND_DESKTOP,"My Func!",invoke GetCommandLine,MB_OK ret EndFunc Try this and post me what's going to happen. |
|||
28 Jan 2013, 14:01 |
|
baldr 28 Jan 2013, 21:12
Kazyaka,
So your includes define macros which expand to function definition, then in main source you invoke those macros in appropriate places, right? I've contrived this: Code: include "Win32AX.Inc" macro .proc [args*] { common macro .code [.args] \{ \common .code .args proc args } .endp fix endp } macro MB text*, caption* { invoke MessageBox, HWND_DESKTOP, text, caption, MB_OK } .proc Hello MB "Hello", invoke GetCommandLine ret .endp .proc Goodbye MB "Goodbye", invoke GetCommandLine ret .endp .code start: MB "Starting", ".proc" stdcall Hello stdcall Goodbye ret .end start |
|||
28 Jan 2013, 21:12 |
|
Spool 29 Jan 2013, 06:58
[ Post removed by author. ]
Last edited by Spool on 17 Mar 2013, 04:51; edited 1 time in total |
|||
29 Jan 2013, 06:58 |
|
Kazyaka 29 Jan 2013, 09:44
baldr,
Quote: So your includes define macros which expand to function definition, then in main source you invoke those macros in appropriate places, right? Quote: Not thoroughly tested though, I just wrote that. Don't you think so? Spool, Yes, we can, but I'll stay with my macros. By the way this thread is a collection of useful functions. |
|||
29 Jan 2013, 09:44 |
|
baldr 29 Jan 2013, 17:08
Kazyaka,
.proc/.endp delegate all stuff to proc/endp just in case you may want to use features of proc/ret, such as calling convention, registers' save/restore and typed parameters. You may send PM in russian if you want to. |
|||
29 Jan 2013, 17:08 |
|
Kazyaka 29 Jan 2013, 21:48
baldr,
Thanks for help. You've explained me everything what I should know about this. I think thread is solved and can be close. I'm going to put all solutions in the first post. |
|||
29 Jan 2013, 21:48 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.