flat assembler
Message board for the users of flat assembler.

Index > Compiler Internals > [bug] out of memory when assembling incomplete macro

Author
Thread Post new topic Reply to topic
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20303
Location: In your JS exploiting you and your system
revolution 01 Nov 2023, 09:19
Code:
rept 1{
rept 5{irp x,<0,1,2,3,4>\{match a=,b=,c=,d=,e,x\\{irp y,<5,6>,<8,7>\\\{\\\}\\}\}}    
Code:
~ fasm test.asm
flat assembler  version 1.73.31  (16384 kilobytes memory)
error: out of memory.    
Try more memory.
Code:
~ fasm test.asm -m 19999
flat assembler  version 1.73.31  (19999 kilobytes memory)
test.asm [2]:
rept 5{irp x,<0,1,2,3,4>\{match a=,b=,c=,d=,e,x\\{irp y,<5,6>,<8,7>\\\{\\\}\\}\}}
test.asm [2] rept [1]:
rept 5{irp x,<0,1,2,3,4>\{match a=,b=,c=,d=,e,x\\{irp y,<5,6>,<8,7>\\\{\\\}\\}\}}
test.asm [2] rept [0]:
rept 5{irp x,<0,1,2,3,4>\{match a=,b=,c=,d=,e,x\\{irp y,<5,6>,<8,7>\\\{\\\}\\}\}}
test.asm [2] irp [2]:
rept 5{irp x,<0,1,2,3,4>\{match a=,b=,c=,d=,e,x\\{irp y,<5,6>,<8,7>\\\{\\\}\\}\}}
test.asm [2] irp [5]:
rept 5{irp x,<0,1,2,3,4>\{match a=,b=,c=,d=,e,x\\{irp y,<5,6>,<8,7>\\\{\\\}\\}\}}
test.asm [2] irp [4]:
rept 5{irp x,<0,1,2,3,4>\{match a=,b=,c=,d=,e,x\\{irp y,<5,6>,<8,7>\\\{\\\}\\}\}}
test.asm [2] match [4]:
rept 5{irp x,<0,1,2,3,4>\{match a=,b=,c=,d=,e,x\\{irp y,<5,6>,<8,7>\\\{\\\}\\}\}}
test.asm [2] irp [4]:
rept 5{irp x,<0,1,2,3,4>\{match a=,b=,c=,d=,e,x\\{irp y,<5,6>,<8,7>\\\{\\\}\\}\}}
test.asm [2] irp [3]:
rept 5{irp x,<0,1,2,3,4>\{match a=,b=,c=,d=,e,x\\{irp y,<5,6>,<8,7>\\\{\\\}\\}\}}
test.asm [2] match [3]:
rept 5{irp x,<0,1,2,3,4>\{match a=,b=,c=,d=,e,x\\{irp y,<5,6>,<8,7>\\\{\\\}\\}\}}
test.asm [2] irp [3]:
rept 5{irp x,<0,1,2,3,4>\{match a=,b=,c=,d=,e,x\\{irp y,<5,6>,<8,7>\\\{\\\}\\}\}}
test.asm [2] irp [2]:
rept 5{irp x,<0,1,2,3,4>\{match a=,b=,c=,d=,e,x\\{irp y,<5,6>,<8,7>\\\{\\\}\\}\}}
test.asm [2] match [2]:
rept 5{irp x,<0,1,2,3,4>\{match a=,b=,c=,d=,e,x\\{irp y,<5,6>,<8,7>\\\{\\\}\\}\}}
test.asm [2] irp [2]:
rept 5{irp x,<0,1,2,3,4>\{match a=,b=,c=,d=,e,x\\{irp y,<5,6>,<8,7>\\\{\\\}\\}\}}
test.asm [2] irp [1]:
rept 5{irp x,<0,1,2,3,4>\{match a=,b=,c=,d=,e,x\\{irp y,<5,6>,<8,7>\\\{\\\}\\}\}}
test.asm [2] match [1]:
rept 5{irp x,<0,1,2,3,4>\{match a=,b=,c=,d=,e,x\\{irp y,<5,6>,<8,7>\\\{\\\}\\}\}}
test.asm [2] irp [1]:
rept 5{irp x,<0,1,2,3,4>\{match a=,b=,c=,d=,e,x\\{irp y,<5,6>,<8,7>\\\{\\\}\\}\}}
error: incomplete macro.    
It got there, but needed a lot of space to figure it out.

However changing the code to add a single extra rept
Code:
rept 1{
rept 6{irp x,<0,1,2,3,4>\{match a=,b=,c=,d=,e,x\\{irp y,<5,6>,<8,7>\\\{\\\}\\}\}}    
Code:
~ fasm test.asm -m 19999
flat assembler  version 1.73.31  (19999 kilobytes memory)
error: out of memory.    
Let's try more memory.
Code:
~ fasm test.asm -m 199999
flat assembler  version 1.73.31  (199999 kilobytes memory)
error: out of memory.    
Let's try more memory.
Code:
~ fasm test.asm -m 499999
flat assembler  version 1.73.31  (499999 kilobytes memory)
error: out of memory.    
Let's try more memory.
Code:
~ fasm test.asm -m 1499999
flat assembler  version 1.73.31  (1499999 kilobytes memory)
error: out of memory.    
It still can't figure it out.

The first rept doesn't have a closing bracket. And there appears to be some sort of exponential expansion of memory usage when a closing curly bracket is missing.
Post 01 Nov 2023, 09:19
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20303
Location: In your JS exploiting you and your system
revolution 02 Nov 2023, 01:17
I recorded the minimum memory requirements to get an outcome that doesn't overflow memory. By changing the value in the second rept between 1 and 5 I found this:
Code:
rept    memory
1       3 kB
2       3 kB
3       7 kB
4       138 kB
5       16817 kB    
I don't know the exact curve function but it looks like it might be a factorial multiplier. Each loop requires a factorial amount more memory than the last. So to estimate the requirement to get a rept value of 6 I estimate it to be 6! * 16817. Which comes to ~12108240 kB. That is 12GB. If that is correct then 32-bit fasm has no chance.

And for rept of 7 it would be ~61TB.
Post 02 Nov 2023, 01:17
View user's profile Send private message Visit poster's website 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-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.