flat assembler
Message board for the users of flat assembler.
Index
> Macroinstructions > Make macro insert code at a different point |
| Author |
|
|
Tomasz Grysztar 14 Jan 2026, 19:57
One of the examples in fasm2 package does it. If you need something similar for fasm 1.x, see the globals package.
|
|||
|
|
macomics 14 Jan 2026, 20:04
Code: ; fasm ./this_file.asm ./this_file.o ; ld -o ./this_file.x64 ./this_file.o format ELF64 macro init_data_section {} section '.text' executable public _start STATIC_STR_COUNTER = 0 macro define_static_str content { local string_label, string_length macro init_data_section \{ init_data_section string_label db content string_length = $ - string_label \} lea rax, [string_label] mov edx, string_length } _start: define_static_str "some string" push rax push rdx define_static_str "another string" mov rsi, rax mov edi, 1 mov eax, 1 syscall pop rdx pop rsi mov edi, 1 mov eax, 1 syscall mov dil, 0 mov eax, 60 syscall section '.data' writeable init_data_section irpv a,init_data_section { resore a } |
|||
|
|
413x1nkp 14 Jan 2026, 22:53
Quote:
Oh thanks! I'm on fasm 1.73.33 and _globals.inc seems like exactly what i want! I'm still not entirely sure how to procedurally generate names for these variables that could be easily cross-referenced across the macro, though.. I tried doing the concatenation of a counter, but it doesn't expand to a value during preprocessing.. Quote:
This actually seems like a perfect solution for my problem!! I somehow forgot how powerful `local' is! I greatly appreciate your help, thanks everyone!! :) Although i'm still curious if evaluating a constant like STATIC_STR_COUNTER to a value would be possible during preprocessing, so that it can be concatenated to a label (kind of like local but DIY) |
|||
|
|
Tomasz Grysztar 15 Jan 2026, 13:26
413x1nkp wrote: Although i'm still curious if evaluating a constant like STATIC_STR_COUNTER to a value would be possible during preprocessing, so that it can be concatenated to a label (kind of like local but DIY) Code: STATIC_STR_COUNTER equ 0 macro define_static_str content { rept 1 this:STATIC_STR_COUNTER, next:STATIC_STR_COUNTER+1 \{ static_data equ str\#this db content STATIC_STR_COUNTER equ next \} } define_static_str "some string" define_static_str "another string" irpv static_string, static_data { static_string } ; result is: ; str0 db 'some string' ; str1 db 'another string' |
|||
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.