flat assembler
Message board for the users of flat assembler.
Index
> Windows > The new macroinstructions for Win32 programming Goto page 1, 2 Next |
Author |
|
decard 13 Jun 2005, 15:12
Great work! Nice that new proc macro allow to put a dot before argument name, as in Fresh sources
|
|||
13 Jun 2005, 15:12 |
|
decard 13 Jun 2005, 16:58
Hre's my SysTray example, with updated macros.
|
|||
13 Jun 2005, 16:58 |
|
Tomasz Grysztar 13 Jun 2005, 17:04
Also, there's a small MASM.INC file which simulates the MASM's syntax for "struct" and "proc" definitions. A sample program:
Code: include 'win32ax.inc' include 'macro\masm.inc' .data _title db 'Win32 program template',0 _class db 'FASMWIN32',0 wc WNDCLASS 0,WindowProc,0,0,NULL,NULL,NULL,COLOR_BTNFACE+1,NULL,_class msg MSG .code WindowProc proc hwnd:DWORD,wmsg:DWORD,wparam:DWORD,lparam:DWORD push ebx esi edi .if [wmsg]=WM_DESTROY invoke PostQuitMessage,0 xor eax,eax .else invoke DefWindowProc,[hwnd],[wmsg],[wparam],[lparam] .endif pop edi esi ebx ret WindowProc endp Start: invoke GetModuleHandle,0 mov [wc.hInstance],eax invoke LoadIcon,0,IDI_APPLICATION mov [wc.hIcon],eax invoke LoadCursor,0,IDC_ARROW mov [wc.hCursor],eax invoke RegisterClass,wc invoke CreateWindowEx,0,_class,_title,WS_VISIBLE+WS_DLGFRAME+WS_SYSMENU,128,128,192,192,NULL,NULL,[wc.hInstance],NULL msg_loop: invoke GetMessage,msg,NULL,0,0 or eax,eax jz end_loop invoke TranslateMessage,msg invoke DispatchMessage,msg jmp msg_loop end_loop: invoke ExitProcess,[msg.wParam] .end Start |
|||
13 Jun 2005, 17:04 |
|
Tomasz Grysztar 16 Jun 2005, 09:30
I have updated the package with further extended the capabilities of "struct" macros - they now allow union and substructures nestable with no limits, for example:
Code: struct LINE union start POINT struct x1 dd ? y1 dd ? ends ends union end POINT struct x2 dd ? y2 dd ? ends ends ends When initializing the values by placing the as parameters to structure, the unions and substructures are treated as single fields. For example: Code: struct FOO a dd ? struct b dd ? c dd ? ends ends my FOO 1,<2,3> The second parameter initializes the substructure, its subparameters initialize the "b" and "c" consecutively. When initializing the union, the parameter given to union is passed as the value to the first field of union (if some of the other fields is larger than the first one, there are undefined bytes placed to pad it to the size of union; the default values for the fields other than first are used only to determine their size). So this: Code: struct BAR a dd ? union b dq ? struct b_low dd ? b_high dd ? ends ends ends foo BAR 1,2 initializes the "b" quadword with value 2. Any default values can be specified in the definition, like: Code: struct COMPOSITE first FOO 1,<2,3> second BAR 1,2 third dd 1 ends |
|||
16 Jun 2005, 09:30 |
|
madmatt 16 Jun 2005, 17:54
I'm having a problem converting my code. When do you use the 'enter' and 'return' macros? also, can you still use multiple 'returns' in the proc\endp macros?
MadMatt |
|||
16 Jun 2005, 17:54 |
|
Tomasz Grysztar 16 Jun 2005, 19:45
You use the "ret" instead of "return" now, the "enter" is not needed at all, for defining locals see the examples in first post above.
If you want to assemble some code using old syntax for proc without converting it, you can try to use some wrappers over the new syntax: Code: macro proc name,[arg] { common proc name arg locals } macro enter { endl } macro return { ret } The locals and returns can be placed anywhere inside the proc in any amount - the only limitation is that declaration of a local must come before you use it. |
|||
16 Jun 2005, 19:45 |
|
Tomasz Grysztar 16 Jun 2005, 20:29
I have extended the "struct" macro again, to allow the simple inheritance of structures (with TASM-like syntax). Simple sample:
Code: struct POINT3D POINT z dd ? ends defines the structure with x, y and z fields. I'm attaching the extended include.
Last edited by Tomasz Grysztar on 16 Jun 2005, 23:13; edited 3 times in total |
|||||||||||
16 Jun 2005, 20:29 |
|
madmatt 16 Jun 2005, 21:57
Thanks Privalov! the macro changes look very promising! (But, are going to require huge changes to all of my extra includes and code examples !WHEW! )
|
|||
16 Jun 2005, 21:57 |
|
Sem 23 Jun 2005, 08:27
A little question:
Code:
proc Start
xor eax,eax
ret
endp
why in code: Code: push ebp mov ebp,esp xor eax,eax leave ret what here proc prolog and epilog for? Would be supported enter and return macros? |
|||
23 Jun 2005, 08:27 |
|
Tomasz Grysztar 23 Jun 2005, 09:44
I thought it would be better to unify this, so if you depended on the fact that [EBP+4] contains the return address, it would be true for all procedures. I can correct it if you need better optimization for such procedures, though to write procedure without any arguments or local variables the "proc" macro is in fact not necessary at all.
For "enter" and "return" see above. You can use the wrappers to compile some old sources, but they are not officially supported now. |
|||
23 Jun 2005, 09:44 |
|
Vasilev Vjacheslav 24 Jun 2005, 09:29
hm, i think something like this will be very useful in fasm
Quote:
|
|||
24 Jun 2005, 09:29 |
|
shoorick 25 Jun 2005, 09:21
i like exactly current macro definitions.
in real: if i create simple procedure, i do not use proc/endp at all if i create large procedure - there is no sence to optimize it with skipping creating stack frame: if you have stack vars/params to access them via esp will cost much expensive then via ebp |
|||
25 Jun 2005, 09:21 |
|
shoorick 25 Jun 2005, 09:46
also in my rules are doing, then reading so when i'd replaced fasm to 1.62 ver, i've been confused with my leave/ret 16 - i'd quikly solved this using retn intstead of ret
|
|||
25 Jun 2005, 09:46 |
|
Tomasz Grysztar 26 Jun 2005, 14:45
One more MASM-like syntax feature added to "local" macro, it now allows to declare local array like this:
Code: local var[100]:WORD |
|||
26 Jun 2005, 14:45 |
|
vid 26 Jun 2005, 18:58
well, these macros are nice as example of FASM's preprocessor power, but i afraid people migrating from MASM will use them by default, which isn't very good. I think you shouldn't include them in standard set, just somewhere on board.
|
|||
26 Jun 2005, 18:58 |
|
farrier 26 Jun 2005, 19:57
vid,
Quote: people migrating from MASM will use them by default, which isn't very good. Do you mean the code generated is not good, or do you think that there should not be any variation from "raw standard" FASM coding style? Either way, I disagree. Theses macro additions make the FASM much more attractive to a much wider user-base. If there is reason why using the MASM-style macros is bad, I'd like to hear it. I have enjoyed the old FASM, but enjoy the NEW FASM even more. farrier _________________ Some Assembly Required It's a good day to code! U.S.Constitution; Bill of Rights; Amendment 1: ... the right of the people peaceably to assemble, ... The code is dark, and full of errors! |
|||
26 Jun 2005, 19:57 |
|
vid 27 Jun 2005, 07:38
reason is same like with many people using MASM after reading few tutorials or migrating from HLL - they don't understand what are they doing. For example many even don't know how the stack works, just because using "local" feature etc. Then they have hard-to-find bugs because of uninitialized variables or wrong usage of SS,SP,BP using pointers to local variables with different segment and many alike.
|
|||
27 Jun 2005, 07:38 |
|
FrozenKnight 27 Jun 2005, 11:22
i've wwritten only a few programs for Fasm but i have an unusual style pf programming (i ocasionally code my own function not using proc) anyway in one program i coded a function inside a proc the problem is that 1.62 inserts a leave before each ret inside a proc so my function inside procs end up leaving the proc before they are suposed to. is there any way i can fix this becasue it's very annoying.
i've fixed the probelm by using retn insted of ret to return from my manual coded function but i'm not really happy with using this method. i personally perfer the old method of using return to return from procs becasue that allows me to use the ret op code. |
|||
27 Jun 2005, 11:22 |
|
Tomasz Grysztar 27 Jun 2005, 13:43
The RETN and RETF are the actual opcodes, the RET is the higher level instruction, defined by Intel to cover those both opcode types, depending on the context (the procedure where they are used). When there is no context, like outside the procedure, RET is equal to RETN in meaning, but when designing the new "proc" macro I preferred to follow the standard and make "ret" be automatically generated exit from procedure, like in TASM etc.
|
|||
27 Jun 2005, 13:43 |
|
Goto page 1, 2 Next < Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.