flat assembler
Message board for the users of flat assembler.
Index
> Windows > About memory buffer |
Author |
|
macomics 19 Nov 2022, 18:58
I do not use the proposed struct macros, but define structures using struc. My solution for this problem
Code: use64 struc assume base*, type& { if ~ type eq virtual at base . type .Length = $ - $$ end virtual else label . at base .Length = 0 end if } struc POINT vX=0, vY=0 { .x dd vX .y dd vY } struc ST { .a dq ? .b dt ? .c dt ? .d POINT ?, ? } ; ... memory_pointer dq ? ; A pointer to the allocated memory block is stored here ; ... memory_area assume rbx, ST cursor assume memory_area.d, POINT ?, ? mov rbx, [memory_pointer] mov rax, [memory_area.a] ; rax = qword [rbx + 0] fld [memory_area.b] ; st0 = tbyte [rbx + 8] fbstp [memory_area.c] ; tbyte [rbx + 18] = bcd(st0) mov edx, [memory_area.d.x] ; edx = dword [rbx + 28] mov [cursor.x], eax ; dword [rbx + 28] = eax ; flat assembler version 1.73.30 (1024 kilobytes memory) ; 1 passes, 30 bytes. ; 00000000 00 00 00 00 00 00 00 00 48 8b 1d f1 ff ff ff 48 |........H......H| ; 00000010 8b 03 db 6b 08 df 73 12 8b 53 1c 89 43 1c |...k..s..S..C.| Last edited by macomics on 20 Nov 2022, 09:11; edited 4 times in total |
|||
19 Nov 2022, 18:58 |
|
Roman 20 Nov 2022, 08:28
macomics wrote: I do not use the proposed struct macros, but define structures using struc. My solution for this problem cursor assume memory_area.d, POINT 0, 0 ;error invalid macro arguments fasmw 1.73 assume cool stuff ! I changed: Code: ppcursor assume memory_area.d, POINT 0, 0 ;and fasm compiled this. ... mov [ppcursor.x], eax |
|||
20 Nov 2022, 08:28 |
|
macomics 20 Nov 2022, 08:53
Corrected typos.
|
|||
20 Nov 2022, 08:53 |
|
AE 20 Nov 2022, 10:49
Thank you!
Is there no way to keep the variable names in their original form? Otherwise I have to rewrite a lot of code where they are used. |
|||
20 Nov 2022, 10:49 |
|
macomics 20 Nov 2022, 13:29
Code: ; ./test.asm use64 macro global name& { if 0 label name end if } struc assume base*, type& { if ~ type eq virtual at base . type .Length = $ - $$ end virtual global . else label . at base .Length = 0 end if } struc POINT vX=0, vY=0 { .x dd vX .y dd vY } struc ST { .a dq ? .b dt ? .c dt ? .d POINT ?, ? } ; ... memory_pointer dq ? ; A pointer to the allocated memory block is stored here ; ... memory_area assume rbx, ST mov rbx, [memory_pointer] mov rax, [.a] ; rax = qword [rbx + 0] fld [.b] ; st0 = tbyte [rbx + 8] cursor assume .d, POINT ?, ? mov [.x], eax ; dword [rbx + 28] = eax global memory_area fbstp [.c] ; tbyte [rbx + 18] = bcd(st0) mov edx, [.d.y] ; edx = dword [rbx + 32] ; $ fasm -m 1024 ./test.asm ./test.bin ; flat assembler version 1.73.30 (1024 kilobytes memory) ; 1 passes, 30 bytes. ; $ hexdump -C ./test.bin ; 00000000 00 00 00 00 00 00 00 00 48 8b 1d f1 ff ff ff 48 |........H......H| ; 00000010 8b 03 db 6b 08 89 43 1c df 73 12 8b 53 20 |...k..C..s..S | |
|||
20 Nov 2022, 13:29 |
|
AE 20 Nov 2022, 13:47
Thanks! |
|||
20 Nov 2022, 13:47 |
|
AE 12 Jan 2023, 04:30
A lot of questions...
At first everything seems very convenient, but as the code is written, inconveniences begin to come to light. It looks like this directive significantly changes how the compiler works.
Maybe it makes sense to include 'MACRO\MASM.INC' and use 'assume reg:STRUCT' ? What is the purpose of 'assumed' macro in MASM.INC ? I'll try to explain again I would like a simple way to "map" the page of allocated memory for variables in the form of a structure. Why structure? Of course, you can access variables by offset, but when adding or changing some of them the offsets will no longer be relevant and you will have to change a lot of places in the code. When accessing structured data, there is no such problem. Simple example: Code: struc PMEM { MajorVersion dd ? MinorVersion dd ? ImagePathName dq ? Mouse POINT ImageName dq ? wc WNDCLASSEX hWnd dq ? MonInfo MONITORINFO } ; alloc some memory mov [MyMem], baseaddr ; save addr ; ... ; Uncomfortable version mov rax, [MyMem+8] ; get ImagePathName ; And I would like at least (or kind of) mov rax, [MyMem.ImagePathName] ; looks like just mov rax, [ImagePathName] ; requires complex code and introduces more confusion and compiler errors A little chaotic, but I hope you understand In general, is there a simple way to do what was intended without changing the usual style of writing code and without breaking the usual behavior of the compiler? Last edited by AE on 12 Jan 2023, 07:00; edited 2 times in total |
|||
12 Jan 2023, 04:30 |
|
macomics 12 Jan 2023, 05:29
AE wrote:
The dots inside the struct macro are attached to each name for you. Just for the sake of this, I don't see the point in using this macro. The compiler's behavior most likely violates global. Try not to use this macro all the time and inside functions, because function macros also change the names of labels. |
|||
12 Jan 2023, 05:29 |
|
AE 12 Jan 2023, 06:20
Yes tis was a typo (extra ?). Thx.
Also can't use it in invoke args, have to use lea Like this Code: lea rcx, [.wc] invoke RegisterClassEx, rcx And seems like it can't handle Code: mov rax, [.MonInfo.rcMonitor.right] ; processed: mov rax,[.MonInfo.rcMonitor.right] ; error: undefined symbol 'IMEM.MonInfo.rcMonitor.right' Quote: Try not to use this macro all the time I just use it ones in the beginning of the code. Maybe there is a simpler and more flexible way to "map" structure to a "memory variable"? Let it be a little less convenient, the main thing is not to create such problems. Something like Code: struc PMEM { MajorVersion dd ? MinorVersion dd ? ImagePathName dq ? Mouse POINT ImageName dq ? wc WNDCLASSEX hWnd dq ? MonInfo MONITORINFO } MyMem PMEM sizeof.PMEM But only in runtime for allocated memory address... |
|||
12 Jan 2023, 06:20 |
|
macomics 12 Jan 2023, 08:14
AE wrote:
AE wrote:
AE wrote: Something like Code: struc assume base*, type& { if ~ type eq virtual at base . type .Length = $ - $$ end virtual else label . at base .Length = 0 end if } struc PMEM { MajorVersion dd ? MinorVersion dd ? ImagePathName dq ? Mouse POINT ImageName dq ? wc WNDCLASSEX hWnd dq ? MonInfo MONITORINFO } MyMem assume rbx mov eax, MyMem.Length If you need to declare only one description, then you can not use the assume structure, but write everything manually. Code: struc PMEM { MajorVersion dd ? MinorVersion dd ? ImagePathName dq ? Mouse POINT ImageName dq ? wc WNDCLASSEX hWnd dq ? MonInfo MONITORINFO } virtual at rbx MyMem PMEM end virtual P.S. Why do you have a parameter passed to it in the form of sizeof.PMEM when declaring MyMem? However there are no formal parameters in the PMEM declaration. |
|||
12 Jan 2023, 08:14 |
|
AE 12 Jan 2023, 08:45
macomics wrote: Show me how you have declared the MONITORINFO structure? Code: struc MONITORINFO { cbSize dd ? rcMonitor RECT ? rcWork RECT ? dwFlags dd ? } Damn, again that "?" in structures types But error have nothing to do with that BTW. So the question is open. Quote: If you need to declare only one description I don't quite understand that sentence. What does "one description" mean? Quote: P.S And I guess in your last example all of the structure members must be prepended with dots for it works with [MyMem.hWnd]. |
|||
12 Jan 2023, 08:45 |
|
AE 12 Jan 2023, 10:43
I eventually came to avoid using macros and just do this
Code: struct MONITORINFO cbSize dd ? rcMonitor RECT rcWork RECT dwFlags dd ? ends struct M MajorVersion dd ? MinorVersion dd ? ImagePathName dq ? Mouse POINT ImageName dq ? wc WNDCLASSEX hWnd dq ? MonInfo MONITORINFO ends mov r15, [IntMem] ;... invoke MonitorFromPoint, qword [r15+M.Mouse], 2 mov [r15+M.MonInfo.cbSize], sizeof.MONITORINFO lea rdx, [r15+M.MonInfo] invoke GetMonitorInfo, rax, rdx not very pretty, but it works and there are no side effects... Thanks anyway, learned a couple of cool tricks! |
|||
12 Jan 2023, 10:43 |
|
macomics 12 Jan 2023, 10:48
AE wrote: Unfortunately, I didn't understand exactly what you are talking about either. Code: ; v - no formal parameters struc PMEM { MajorVersion dd ? MinorVersion dd ? ImagePathName dq ? Mouse POINT ImageName dq ? wc WNDCLASSEX hWnd dq ? MonInfo MONITORINFO } ; v - actual parameter for PMEM MyMem PMEM sizeof.PMEM |
|||
12 Jan 2023, 10:48 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.