flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > How to use macro with multi line args? For Stack vars define

Author
Thread Post new topic Reply to topic
Geist-Z



Joined: 18 Sep 2026
Posts: 3
Location: China
Geist-Z 18 Sep 2026, 05:37
Key problem is the Macro-Args with mlti line,Just copy-paste is enough

macro SUB_RSP vars{
vars
PRINT_VAL
}


entry _start
_start:
SUB_RSP {mov rax,5
PRINT_VAL
}

main.asm [551]:
SUB_RSP {mov rax,5
error: invalid macro arguments.

Try <>,&,\,withspace,withoutspace didn't work.
Read posts didn't found.

Originally Want to define vars on stack without too many lines

macro SString bodys {
virtual at rsp
;; str String
;; str_size =$-str
bodys
end virtual

sub rsp,str_size
mmap 0,STRING_INIT_CAP,PROT_READ or PROT_WRITE,MAP_PRIVATE or MAP_ANONYMOUS,-1,0
cmp r0,MAP_FAILED
je gg
mov [str#.items],r0
add [str#.capacity],STRING_INIT_CAP
add rsp,str_size
}
Post 18 Sep 2026, 05:37
View user's profile Send private message Send e-mail Reply with quote
Geist-Z



Joined: 18 Sep 2026
Posts: 3
Location: China
Geist-Z 18 Sep 2026, 05:45
Here is my Liunx x86_64 syscall macro
Free to use

;;rdi,rsi,rdx,r10,r8,r9
sc_var_pos = 0
macro sc_var number, [args] {
common
mov r0, number
forward
if ~ args eq
if sc_var_pos = 0
mov r1, args
push r1
else if sc_var_pos = 1
mov r2, args
push r2
else if sc_var_pos = 2
mov r3, args
push r3
else if sc_var_pos = 3
mov r4, args
push r4
else if sc_var_pos = 4
mov r5, args
push r5
else if sc_var_pos = 5
mov r6, args
push r6
end if
end if
sc_var_pos = sc_var_pos + 1
common
sc
if sc_var_pos > 5
pop r6
end if
if sc_var_pos > 4
pop r5
end if
if sc_var_pos > 3
pop r4
end if
if sc_var_pos > 2
pop r3
end if
if sc_var_pos > 1
pop r2
end if
if sc_var_pos > 0
pop r1
end if

sc_var_pos = 0
}
Post 18 Sep 2026, 05:45
View user's profile Send private message Send e-mail Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 21110
Location: In your JS exploiting you and your system
revolution 18 Sep 2026, 05:59
The general case is this:
Code:
macro x [args] {
 forward
 args
}

x \
  nop, \
  ud2

x inc ax, <add bx,cx>, \
  cpuid, hlt    
Code:
00000000  90                nop
00000001  0F0B              ud2
00000003  40                inc ax
00000004  01CB              add bx,cx
00000006  0FA2              cpuid
00000008  F4                hlt    
Post 18 Sep 2026, 05:59
View user's profile Send private message Visit poster's website Reply with quote
Geist-Z



Joined: 18 Sep 2026
Posts: 3
Location: China
Geist-Z 18 Sep 2026, 06:15
Huge Thanks! ypa!!!
Post 18 Sep 2026, 06:15
View user's profile Send private message Send e-mail Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2026, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.