flat assembler
Message board for the users of flat assembler.
![]() Goto page 1, 2 Next |
Author |
|
macomics 10 Apr 2025, 13:54
Code: invoke MessageBox, HWND_DESKTOP, <"First string", "Second string", "Third string">, "Test", MB_OK or MB_ICONINFORMATION Code: EOLN fix 0xd,0xa struc StringA txt& { label . db txt label .length at ( $ - . ) db 0 label .bytes at ( $ - . ) } ; ... invoke WriteFile, [hFile], addr [a], a.length, addr [nWriten], NULL ; ... a StringA "First string", EOLN, "Second string", EOLN, "Third string" |
|||
![]() |
|
a 10 Apr 2025, 16:23
kake_zinger wrote: My newbie brain hurts and wonders... "Joined: 15 Jul 2004" |
|||
![]() |
|
kake_zinger 12 Apr 2025, 12:04
a wrote: "Joined: 15 Jul 2004" I only ever used Fasm as a compiler for my pc boot environment project (which was fun), never had a need to touch macros nor Windows programming, so a definite newbie at those now. Besides in nearly 20 years it seems it's possible to forget most of even 32bit asm ![]() macomics wrote: <examples> Thanks for those, maybe they were the secret sauce to get my brain geared towards what I'd really need: A way to conveniently use throwaway strings within code without endless label inventing, or even keeping track of a serial#. Something like: Code: jmp @@ @1: db 'Here lies a very deep, introspective string,'\ "which may even continue on multiple lines.',13,10,0 @2: db $ - @1 @@: mov rcx, [@2] mov rdx, @1 [...call/invoke something...] I notice Thomas made some macros which might fit the purpose at https://board.flatassembler.net/topic.php?p=190642#190642 but for Fasmg only. Any chance those could be translated to plain Fasm? Even @bN only would be great for simple string definitions, although some complicated loop constructs might like @fN as well. Since there have been proposals for this, and the Fasmg macro, many AI's seem to think this is a reality already, so might as well make it a reality. Writing code in a debugger one has unlimited anon labels in the form of memory addresses. A whole range of hex wouldn't be bad, @1-@f, but what about going base 36 and all the way from @0 to @z ![]() |
|||
![]() |
|
macomics 12 Apr 2025, 13:06
Code: jmp @f @1: db 'Here lies a very deep, introspective string,',\ "which may even continue on multiple lines.",13,10,0 @2: dq $ - @1 @@: mov rcx, [@2] lea rdx, [@1] [...call/invoke something...] https://board.flatassembler.net/topic.php?t=21545&postdays=0&postorder=asc&start=0 |
|||
![]() |
|
Tomasz Grysztar 12 Apr 2025, 13:23
kake_zinger wrote: I notice Thomas made some macros which might fit the purpose at Code: macro @INIT name,prefix { macro name tail& \{ match label, prefix#f \\{ label tail prefix#b equ prefix#f prefix#r equ prefix#f \\} \local ..anonymous prefix#f equ ..anonymous \} define prefix#f name } rept 10 i:0 { @INIT @#i,@#i } |
|||
![]() |
|
a 12 Apr 2025, 13:55
kake_zinger wrote: 'Here lies a very deep, introspective string,'\ if you want for multi-line macro to automatically insert a new-line then: Code: macro PrintString [args] { common local startm, endm, count count = 0 jmp endm startm: forward count=count+1 forward db args if ~ count = 1 count=count-1 db 0xd,0xa end if common db 0 endm: mov rax, startm ; string address mov rcx, endm - startm - 1 ; string size (minus 1 null) } PrintString "Here lies a very deep, introspective string",\ "which may even continue on multiple lines." |
|||
![]() |
|
a 12 Apr 2025, 14:12
my macro seems to be too large, because it counts the amount of the parameters
if only fasm would had a convenient way to detect the last parameter, u know by something like this: Code: if last db 0 end if if not last db 0xA end if or better yet: Code: if current_param = -1 db 0 end if or it would be nice having an % variable to return something |
|||
![]() |
|
revolution 12 Apr 2025, 14:26
If the string is a counted length then you don't need the 0 terminator.
Or alternatively, if the string is zero terminated then you don't need the length. |
|||
![]() |
|
a 12 Apr 2025, 14:41
revolution wrote: If the string is a counted length then you don't need the 0 terminator. I think kake_zinger wants a macro to cover a both cases at the same time, so that you dont have to bother with it, a swiss knife kind of macro kake_zinger wrote: A way to conveniently use throwaway strings within code without endless label inventing, or even keeping track of a serial#. |
|||
![]() |
|
macomics 12 Apr 2025, 15:47
revolution wrote: If the string is a counted length then you don't need the 0 terminator. Controversial statements, at least because then the strings will not be interchangeable and you will have to spend time calculating the length. |
|||
![]() |
|
Tomasz Grysztar 12 Apr 2025, 18:40
a wrote: if only fasm would had a convenient way to detect the last parameter, u know by something like this: ... Code: macro PrintString args& local startm, endm jmp endm startm: iterate item, args db item if % < %% db 0xd,0xa end if end iterate db 0 endm: mov rax, startm mov rcx, endm - startm - 1 end macro |
|||
![]() |
|
kake_zinger 13 Apr 2025, 08:27
macomics wrote:
I like to define labeled strings like this because it covers both cases at once, depends on whether one uses WriteConsole/File or printf more which one is a better default: Code: ; Better for WriteConsole/File, easy usage @@: msg_debug dq @f - @b - 8 ; current data size (dq) needs to be subbed db 'Attempting to write a console message...', 13, 10, 0 ; String always at msg_debug + datatype_size; pick one type and stick with it ; ; Note the next anon label is still part of the definition ; ; Better for printf but need to specify size with length operations @@: dq @f - @b - 8 ; Address always at string_label - datatype_size msg_debug_3 db 'Attempting to write a console message yet again...', 13, 10, 0 @@: ; If using label after length version, size must be specified when using length: ; mov r8, qword [msg_debug_3 - 8] I don't mind sacrificing 8 bytes (or whatever max string size type is used) for always having a precalculated value for the length in case it's needed. |
|||
![]() |
|
kake_zinger 13 Apr 2025, 09:31
Tomasz Grysztar wrote: You can translate the macros made for fasmg quite directly Please don't be oblivious to your own genius-level skill and experience, that's just about an impossible task for someone who's new to Fasm macros, probably even for intermediate level (as testified by the lack of solutions this far, or did my searches fail? Please do prove me wrong..). |
|||
![]() |
|
macomics 13 Apr 2025, 09:35
kake_zinger wrote: Please do prove me wrong..). The lack of solutions for fasm1 rather suggests that macros are easy to rewrite on fasm1. So they don't share the obvious, but simply rewrite it and use it. |
|||
![]() |
|
Tomasz Grysztar 13 Apr 2025, 11:38
kake_zinger wrote: (as testified by the lack of solutions this far, or did my searches fail? Please do prove me wrong..). |
|||
![]() |
|
Roman 14 Apr 2025, 10:00
very interesting.
Quote:
I don't know about colon. This is news to me. Code: ;fasm do this ? if a eq colon or eqtype do some end if what other reserved words are there for macros? |
|||
![]() |
|
revolution 14 Apr 2025, 10:30
There is nothing special about colon. You can also write the macro like this:
Code: macro @@@ arg { } |
|||
![]() |
|
Roman 14 Apr 2025, 12:25
ok.
How do many @ in macro ? Something like this macro @,5 { created macro @@@@@ arg \{\} } ;in code @@@@@: |
|||
![]() |
|
kake_zinger 14 Apr 2025, 18:35
Tomasz Grysztar wrote: There is one from 2006, even. Oh that's a bait'n'switch, it does not implement numbered @0...@9 macros with jumping at them with @f1...9 / @b1...9 like you quoted earlier from Fasm2 macros. Seems I was right in my assessment of the conversion being non-trivial and none posted public this far (but maybe 19 years is too short of a time for settling such trivial matters). But it was a good hook for getting someone to explore Fasm2, which I'm now doing, and enjoying Code: include '@@.inc' immensely. Too bad about them ordinary folks with their plain Fasm, no multi-anon-jmp-macros for you... (just wait another 19 years and they might arrive!) |
|||
![]() |
|
Goto page 1, 2 Next < Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.