flat assembler
Message board for the users of flat assembler.

Index > Projects and Ideas > fasm 2 as a set of scripts and headers for fasmg

Goto page Previous  1, 2
Author
Thread Post new topic Reply to topic
vityacv



Joined: 27 Oct 2012
Posts: 16
vityacv 20 Aug 2025, 18:56
Having issue with this sample on FASM 2 - Custom error: operand sizes do not match.
Code:
include 'win64w.inc'
format pe64

struct Test2
a1 rd 1
ends

struct Test3
a1 rd 1
a2 rd 1
a3 rd 1
a4 rd 1
a5 rd 1
ends

struct Test1
a1 rd 1
a2 Test2
a3 Test3
ends

struct Test4
a1 rd 1
a2 rd 1
ends

virtual at 0
V1 Test4
V2 Test4
end virtual

mov esi,[rax+rax+Test1.a3+V1.a1]
ret
    

FASM 1 compiles without error
Post 20 Aug 2025, 18:56
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8534
Location: Kraków, Poland
Tomasz Grysztar 20 Aug 2025, 19:11
vityacv wrote:
Having issue with this sample on FASM 2 - Custom error: operand sizes do not match.
Code:
include 'win64w.inc'
format pe64

struct Test2
a1 rd 1
ends

struct Test3
a1 rd 1
a2 rd 1
a3 rd 1
a4 rd 1
a5 rd 1
ends

struct Test1
a1 rd 1
a2 Test2
a3 Test3
ends

struct Test4
a1 rd 1
a2 rd 1
ends

virtual at 0
V1 Test4
V2 Test4
end virtual

mov esi,[rax+rax+Test1.a3+V1.a1]
ret
    

FASM 1 compiles without error
The "Test1.a3" has associated size (20 bytes), as the STRUCT macro in fasm2 has an added feature of sizing all these labels properly. This was missing in fasm's implementation, because it was not really possible to implement there except for a small set of supported sizes.

If you'd prefer to not have this feature, comment out the portion of "instantiate" macro:
Code:
                arrange tmp, =label instance; : sname.=__size__    
Another workaround is to rearrange the expression so that the intended size comes first.
Post 20 Aug 2025, 19:11
View user's profile Send private message Visit poster's website Reply with quote
vityacv



Joined: 27 Oct 2012
Posts: 16
vityacv 04 Dec 2025, 17:24
Code:
format binary
use64

ret
align 16

flat assembler  version g.l04h
1 pass, 1 byte.    


Getting 1 byte output instead of 16, fasm 1 have same result. Also fasm 1 creates output file with .bin extension, should fasm 2 do the same?
Post 04 Dec 2025, 17:24
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8534
Location: Kraków, Poland
Tomasz Grysztar 04 Dec 2025, 18:13
vityacv wrote:
Getting 1 byte output instead of 16, fasm 1 have same result.
It's compatible then, isn't it?

But with fasm2 you can also do this:
Code:
align 16, 90h    
See the comments in the package.
vityacv wrote:
Also fasm 1 creates output file with .bin extension, should fasm 2 do the same?
This small difference is actually handy when testing one against the other. Of course adding a simple AS in the headers could bridge this gap, too.
Post 04 Dec 2025, 18:13
View user's profile Send private message Visit poster's website Reply with quote
vityacv



Joined: 27 Oct 2012
Posts: 16
vityacv 22 Apr 2026, 15:46
With this sample and triggering build without the 32.ico in folder
Code:
format pe64
entry Main

include 'win64w.inc'
include 'encoding\utf8.inc'

Main:
ret

align 8
test1 du '1111111111111111111111111111111',0

align 8
data fixups
end data

align 8
data resource
directory RT_ICON,icons,RT_GROUP_ICON,group_icons
resource icons,32,LANG_NEUTRAL,icon_32
resource group_icons,1,LANG_NEUTRAL,main_icon
icon main_icon,icon_32,'32.ico'
end data

    

Getting:
Quote:
flat assembler version g.l4gs
Error: not enough memory to complete the assembly.


It also can freeze when executed multiple times.
Post 22 Apr 2026, 15:46
View user's profile Send private message Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 4503
Location: vpcmpistri
bitRAKE 22 Apr 2026, 20:38
Code:
> fasm2 -v 2 -e 5 vityacv.error.asm
flat assembler  version g.l2fx
flat assembler  version g.l5p0

vityacv.error.asm [23]:
        icon main_icon,icon_32,'32.ico'
macro icon [4]:
        file icon_file:6,16
Processed: file '32.ico':6,16
Error: source file '32.ico' not found.
vityacv.error.asm [23]:
        icon main_icon,icon_32,'32.ico'
macro icon [9]:
        data#% file icon_file:position,size
Processed: data#1 file '32.ico':position,size
Error: source file '32.ico' not found.
vityacv.error.asm [23]:
        icon main_icon,icon_32,'32.ico'
macro icon [16]:
        file icon_file:6,12
Processed: file '32.ico':6,12
Error: source file '32.ico' not found.    
... is what I'm getting with a couple versions. (Just updated?)
(Of course, it builds with icon file.)

_________________
¯\(°_o)/¯ AI may [not] have aided with the above reply.
Post 22 Apr 2026, 20:38
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8534
Location: Kraków, Poland
Tomasz Grysztar 23 Apr 2026, 08:29
bitRAKE wrote:
... is what I'm getting with a couple versions. (Just updated?)
The issue was non-deterministic. The FILE directive did not zero the memory reserved for data from file, and .ICO parser was LOAD-ing a length field from there. It was then allocating the memory for icon data with a "random" size.

In particular, if you've been testing both the new version (which clears the reserved block) and the old one, the old might have been reusing a zeroed block, masking the problem.
Post 23 Apr 2026, 08:29
View user's profile Send private message Visit poster's website Reply with quote
vityacv



Joined: 27 Oct 2012
Posts: 16
vityacv 29 May 2026, 16:18
Code:
format pe64

Main:
mov rcx,test1.size
mov rdx,test1  

mov rcx,test2.size
mov rdx,test2
ret

test1 db 1
.size = $-test1

test2 0x90
.size = $-test2
    

flat assembler version g.l5p0
says
/tmp/fasm2/test.asm [4]:
mov rcx,test1.size
mov? [3] x86.parse_operand@src [32] (CALM)
Processed: mov rcx,test1.size
Error: symbol 'test1.size' is undefined or out of scope

But the issue is in test2? Also will sizeof be supported for db etc.?
Post 29 May 2026, 16:18
View user's profile Send private message Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 4503
Location: vpcmpistri
bitRAKE 29 May 2026, 18:56
Often an error has knock-on effects - causes other errors:
Code:
> fasm2 -e 4 vityacv.test.asm
flat assembler  version g.l5p0
vityacv.test.asm [6]:
        mov rcx,test1.size
mov? [3] x86.parse_operand@src [32] (CALM)
Processed: mov rcx,test1.size
Error: symbol 'test1.size' is undefined or out of scope.
vityacv.test.asm [9]:
        mov rcx,test2.size
mov? [3] x86.parse_operand@src [32] (CALM)
Processed: mov rcx,test2.size
Error: symbol 'test2.size' is undefined or out of scope.
vityacv.test.asm [10]:
        mov rdx,test2
mov? [3] x86.parse_operand@src [32] (CALM)
Processed: mov rdx,test2
Error: symbol 'test2' is undefined or out of scope.
vityacv.test.asm [16]:
        test2 0x90
? [4]
Processed: test2 0x90
Error: illegal instruction.    
... this means the error on the top of the error stack is not always the best indication of the exact location, imho.
Post 29 May 2026, 18:56
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8534
Location: Kraków, Poland
Tomasz Grysztar 30 May 2026, 18:36
bitRAKE wrote:
... this means the error on the top of the error stack is not always the best indication of the exact location, imho.
I've been in fact considering adding a default "-e1000" to fasm2 scripts (it could still be overridden by another "-e" passed from the fasm2 arguments).
Post 30 May 2026, 18:36
View user's profile Send private message Visit poster's website Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 4503
Location: vpcmpistri
bitRAKE 03 Jun 2026, 23:44
I wonder if defaulting to the number of passes(+1?) would be more effective? (-e 0) Or is this too hopeful and there is no relationship?
Post 03 Jun 2026, 23:44
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8534
Location: Kraków, Poland
Tomasz Grysztar 04 Jun 2026, 09:42
There is no relationship at all. The errors are collected from a single pass (the last one that was done). And there may be many errors that disappear once the proper values are resolved, so the number of errors usually goes down with consecutive passes.
Post 04 Jun 2026, 09:42
View user's profile Send private message Visit poster's website Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 4503
Location: vpcmpistri
bitRAKE 04 Jun 2026, 17:22
I get that - the solver is trying to resolve unknowns, bumping pass counter to give it another try. Eventually, another pass doesn't help. My sense is the maximum unknown cascade would be the pass count, or less. Many errors are outside the pass resolution: circular definitions, syntax errors, etc.

I need to gather an error corpus and dive into this deeper at some point.

_________________
¯\(°_o)/¯ AI may [not] have aided with the above reply.
Post 04 Jun 2026, 17:22
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8534
Location: Kraków, Poland
Tomasz Grysztar 04 Jun 2026, 18:23
bitRAKE wrote:
I get that - the solver is trying to resolve unknowns, bumping pass counter to give it another try. Eventually, another pass doesn't help. My sense is the maximum unknown cascade would be the pass count, or less. Many errors are outside the pass resolution: circular definitions, syntax errors, etc.

I need to gather an error corpus and dive into this deeper at some point.
Consider this simple example:
Code:
if x
+
+
+
x=2
end if
x=1    
It generates only one error in the first pass, three errors in the second one, and goes back to a single error in the third:
Code:
>fasmg a.asm -e100 -p1
flat assembler  version g.l5p0
Error: could not generate code within the allowed number of passes.
a.asm [1]:
        if x
Processed: if x
Error: symbol 'x' is undefined or out of scope.

>fasmg a.asm -e100 -p2
flat assembler  version g.l5p0
Error: could not generate code within the allowed number of passes.
a.asm [2]:
        +
Processed: +
Error: illegal instruction.
a.asm [3]:
        +
Processed: +
Error: illegal instruction.
a.asm [4]:
        +
Processed: +
Error: illegal instruction.

>fasmg a.asm -e100 -p3
flat assembler  version g.l5p0
a.asm [1]:
        if x
Processed: if x
Error: symbol 'x' is undefined or out of scope.    
The number of errors may go up and down for various reasons and you can easily manipulate it like above.
Post 04 Jun 2026, 18:23
View user's profile Send private message Visit poster's website Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 4503
Location: vpcmpistri
bitRAKE 05 Jun 2026, 05:47
Tomasz Grysztar wrote:
The number of errors may go up and down for various reasons and you can easily manipulate it like above.
That is why I was talking about p->inf; because the temporal dynamics of errors is non-linear. (If we think of p as time - which it is.) What are the pathological cases that maximize errors. Length of source is a factor. Shouldn't the pathological cases follow e ~= Np? Real world would be under that.

_________________
¯\(°_o)/¯ AI may [not] have aided with the above reply.
Post 05 Jun 2026, 05:47
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8534
Location: Kraków, Poland
Tomasz Grysztar 05 Jun 2026, 08:29
bitRAKE wrote:
That is why I was talking about p->inf; because the temporal dynamics of errors is non-linear. (If we think of p as time - which it is.) What are the pathological cases that maximize errors. Length of source is a factor. Shouldn't the pathological cases follow e ~= Np? Real world would be under that.
This gives you any number of errors in a specifically chosen pass:
Code:
TARGET_PASS = 23
TARGET_ERRORS = 57

LAST_PASS = TARGET_PASS - 1

if ~ defined PASS
        PASS = 1
else if PASS >= LAST_PASS
        PASS = LAST_PASS
        repeat TARGET_ERRORS
                -
        end repeat
else
        PASS = PASS + 1
end if    
Therefore there are no constraints on the "pathological cases".
Post 05 Jun 2026, 08:29
View user's profile Send private message Visit poster's website Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 4503
Location: vpcmpistri
bitRAKE 05 Jun 2026, 09:10
Thank you, nice example for the corpus.

(p) < TARGET_PASS does one thing and (p) >= TARGET_PASS does another.
Post 05 Jun 2026, 09:10
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:  
Goto page Previous  1, 2

< 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.