flat assembler
Message board for the users of flat assembler.
Index
> Windows > assume in fasm |
Author |
|
JohnFound 22 Jul 2004, 16:12
The most clear and readable approach is:
Code: mov eax, [esi+PAINTSTRUCT.hdc] Regards. |
|||
22 Jul 2004, 16:12 |
|
Tomasz Grysztar 22 Jul 2004, 16:44
And my recommendation always was to use dedicated labels:
Code: mov esi,buff virtual at esi ps_in_buff PAINTSTRUCT ; use the name that makes it the most clear for you end virtual mov [ps_in_buff.hdc],0 |
|||
22 Jul 2004, 16:44 |
|
vid 22 Jul 2004, 19:05
my recommendation is to always write [esi + PAINTSTRUCT.member], you always know what you are doing and typing 6 more characters isn't that painful.
|
|||
22 Jul 2004, 19:05 |
|
Tomasz Grysztar 22 Jul 2004, 19:14
But more abstract way with the virtual directive allows you to write more universal code, easier to modify and maintain.
|
|||
22 Jul 2004, 19:14 |
|
crc 23 Jul 2004, 00:52
I actually find the use of the virtual directive more confusing. It abstracts a little too far from the code IMO.
|
|||
23 Jul 2004, 00:52 |
|
djca 23 Jul 2004, 07:52
Ok thanks for the replies.
The first metod is maybe more clear but when using it you have to know the size of every member in the structure: mov dword [esi+STRUCT.first],5 mov byte [esi+STRUCT.second],99 exept when using registers mov [esi+STRUCT.third],eax Actually I write a program which uses one buffer for many different structutres PAINTSTRUCT, MSG, WNDCLASS and so on. These structures are used only for temporaly storage of data. This saves some more memory and disk size . Here is an example (this is the Template example in fasm package): ; template for program using standard Win32 headers format PE GUI 4.0 entry start include '%fasminc%\win32a.inc' macro Dim var,struct { virtual at TempBuff var struct end virtual } section '.data' data readable writeable _title db 'Win32 program template',0 _class db 'FASMWIN32',0 mainhwnd dd ? hinstance dd ? TempBuff rb 64 ; Temporaly buffer Dim msg,MSG Dim wc,WNDCLASS section '.code' code readable executable start: invoke GetModuleHandle,0 mov [hinstance],eax invoke LoadIcon,0,IDI_APPLICATION mov [wc.hIcon],eax invoke LoadCursor,0,IDC_ARROW mov [wc.hCursor],eax mov [wc.style],0 mov [wc.lpfnWndProc],WindowProc mov [wc.cbClsExtra],0 mov [wc.cbWndExtra],0 mov eax,[hinstance] mov [wc.hInstance],eax mov [wc.hbrBackground],COLOR_BTNFACE+1 mov [wc.lpszMenuName],0 mov [wc.lpszClassName],_class invoke RegisterClass,wc invoke CreateWindowEx,0,_class,_title,WS_VISIBLE+WS_DLGFRAME+WS_SYSMENU,128,128,192,192,NULL,NULL,[hinstance],NULL mov [mainhwnd],eax 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] proc WindowProc, hwnd,wmsg,wparam,lparam push ebx esi edi cmp [wmsg],WM_DESTROY je .wmdestroy .defwndproc: invoke DefWindowProc,[hwnd],[wmsg],[wparam],[lparam] jmp finish .wmdestroy: invoke PostQuitMessage,0 xor eax,eax finish: pop edi esi ebx return endp section '.idata' import data readable writeable library kernel,'KERNEL32.DLL',\ user,'USER32.DLL' import kernel,\ GetModuleHandle,'GetModuleHandleA',\ ExitProcess,'ExitProcess' import user,\ RegisterClass,'RegisterClassA',\ CreateWindowEx,'CreateWindowExA',\ DefWindowProc,'DefWindowProcA',\ GetMessage,'GetMessageA',\ TranslateMessage,'TranslateMessage',\ DispatchMessage,'DispatchMessageA',\ LoadCursor,'LoadCursorA',\ LoadIcon,'LoadIconA',\ PostQuitMessage,'PostQuitMessage' |
|||
23 Jul 2004, 07:52 |
|
Tomasz Grysztar 23 Jul 2004, 08:03
Quote: The first metod is maybe more clear but when using it you have to know the size of every member in the structure: No, it's not true in the case of FASM. The size of data can determined from the label placed anywhere inside the memory operand. This code Code: mov [esi+PAINTSTRUCT.hdc],0 will be assembled correctly. |
|||
23 Jul 2004, 08:03 |
|
LocoDelAssembly 29 Jul 2005, 19:44
Code: mov esi,buff virtual at esi ps_in_buff PAINTSTRUCT ; use the name that makes it the most clear for you end virtual mov [ps_in_buff.hdc],0 If I don't want to use ps_in_buff any more, how can I undefine it? If it's not possible, how can I prevent the use of ps_in_buff from others parts of the code? |
|||
29 Jul 2005, 19:44 |
|
Tomasz Grysztar 29 Jul 2005, 20:52
You can do it in the same way as the "locals" directive does it for "proc", it does need a bit complex macros to be used, though.
|
|||
29 Jul 2005, 20:52 |
|
LocoDelAssembly 29 Jul 2005, 21:33
YEEEEAAAAAAHHHHHH, the problem was I forgot to change "mov [ps_in_buffer.hdc], 0" to "mov [ps_in_buff#.hdc], 0"
This is the code now: Code: macro m{ local ps_in_buff mov esi,buff virtual at esi ps_in_buff PAINTSTRUCT ; use the name that makes it the most clear for you end virtual mov [ps_in_buff#.hdc],0 }m purge m I'm sorry you already told me that the dot is part of the name a few months ago but I am still not accustomed Thanks Tomasz Last edited by LocoDelAssembly on 29 Jul 2005, 21:44; edited 1 time in total |
|||
29 Jul 2005, 21:33 |
|
farrier 29 Jul 2005, 21:35
This is what I use:
Code: NMHDR.hwndFrom fix dword [EBX+0] NMHDR.idFrom fix dword [EBX+4] NMHDR.code fix dword [EBX+8] wmnotify: mov ebx, [lparam] .if NMHDR.code, e, TTN_NEEDTEXT invoke LoadString, [hinstance], NMHDR.idFrom, szBuff, szBuff.size mov TOOLTIPTEXT.lpszText, szBuff xor eax, eax .else mov eax, NMHDR.hwndFrom .if eax, e, [hList] .if NMHDR.code, e, LVN_COLUMNCLICK .if NM_LISTVIEW.iSubItem, e, 1 ;sort listview here .endif ... I did this because "virtual" was causing problems with jmp's from one side of the virtual to the other. But after a while, I liked the way it looked, and it made sense to me when I looked at the code. With the new features of the FASM, maybe I should more properly use equ instead of fix? 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! |
|||
29 Jul 2005, 21:35 |
|
LocoDelAssembly 29 Jul 2005, 21:55
I don't know but if you can't undefine those fixes then you can use those symbols in other places of the code. I think using a macro is very clear because I define the macro in the same place I'm using it an then I purge it immediately.
Thanks for the idea anyway |
|||
29 Jul 2005, 21:55 |
|
LocoDelAssembly 30 Jul 2005, 00:23
I found another way, if I put "local ps_in_buff." (with the dot) there is no need of "#"
|
|||
30 Jul 2005, 00:23 |
|
Tomasz Grysztar 30 Jul 2005, 06:22
If you use "local ps_in_buff." you don't make "ps_in_buff" local at all - the "ps_in_buff." is a different name than "ps_in_buff".
You can however use the NASM-like label localization for this purposes, too: Code: some_global_label: mov esi,buff virtual at esi .ps_in_buff PAINTSTRUCT end virtual mov [.ps_in_buff.hdc],0 |
|||
30 Jul 2005, 06:22 |
|
LocoDelAssembly 30 Jul 2005, 14:10
Quote: I'm sorry you already told me that the dot is part of the name a few months ago but I am still not accustomed It's very clear that I don't want to understand that yet Thanks again |
|||
30 Jul 2005, 14:10 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.